Skip to content

Commit

Permalink
Replaced msgpack-lite with msgpack5 (crossbario#330)
Browse files Browse the repository at this point in the history
* Replaced msgpack-lite with msgpack5

This fixes subscription IDs being sent to the router as floats due to
msgpack-lite's buggy handling of large numbers.

* Removed obsolete msgpack workaround
  • Loading branch information
agronholm authored and oberstet committed Nov 23, 2017
1 parent dd43b1b commit e59da86
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/autobahn.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var pjson = require('../package.json');
var when = require('when');
//var fn = require("when/function");

var msgpack = require('msgpack-lite');
var msgpack = require('msgpack5');
var cbor = require('cbor');
var nacl = require('tweetnacl');

Expand Down
18 changes: 5 additions & 13 deletions lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,19 @@ JSONSerializer.prototype.unserialize = function (payload) {
exports.JSONSerializer = JSONSerializer;


// https://github.com/kawanet/msgpack-lite/
// https://github.com/kawanet/int64-buffer
var msgpack = require('msgpack-lite');

// this is needed for correct msgpack serialization of WAMP session IDs
var Uint64BE = require('int64-buffer').Uint64BE;
// https://github.com/mcollina/msgpack5
var msgpack = require('msgpack5')({forceFloat64: true});

function MsgpackSerializer() {
this.SERIALIZER_ID = 'msgpack';
this.BINARY = true;
this.codec = msgpack.createCodec();

// msgpack: Uint64BE ensures that ID is encoded as int instead of double
this.newid = function () { return new Uint64BE(newid()); };
this.newid = newid;
}

MsgpackSerializer.prototype.serialize = function (obj) {
try {
var payload = msgpack.encode(obj, {codec: this.codec});
var payload = msgpack.encode(obj);
return payload;
} catch (e) {
log.warn('MessagePack encoding error', e);
Expand All @@ -84,9 +78,7 @@ MsgpackSerializer.prototype.serialize = function (obj) {

MsgpackSerializer.prototype.unserialize = function (payload) {
try {
// need to encapsulate ArrayBuffer into Uint8Array for msgpack decoding
// https://github.com/kawanet/msgpack-lite/issues/44
var obj = msgpack.decode(new Uint8Array(payload), {codec: this.codec});
var obj = msgpack.decode(payload);
return obj;
} catch (e) {
log.warn('MessagePack decoding error', e);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
},
"dependencies": {
"crypto-js": ">= 3.1.8",
"int64-buffer": ">= 0.1.9",
"msgpack-lite": ">= 0.1.26",
"msgpack5": ">= 3.6.0",
"cbor": ">= 3.0.0",
"tweetnacl": ">= 0.14.3",
"when": ">= 3.7.7",
Expand Down

0 comments on commit e59da86

Please sign in to comment.