diff --git a/src/decoder.js b/src/decoder.js index f55451f25..7f58ab1a8 100644 --- a/src/decoder.js +++ b/src/decoder.js @@ -72,7 +72,7 @@ function decoder(mtype) { ("}"); if (types.long[field.keyType] !== undefined) gen - ("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref); + ("%s[k.toString()]=value", ref); else gen ("%s[k]=value", ref); diff --git a/tests/comp_maps-long-key.js b/tests/comp_maps-long-key.js new file mode 100644 index 000000000..a2a994435 --- /dev/null +++ b/tests/comp_maps-long-key.js @@ -0,0 +1,37 @@ +var tape = require("tape"); + +var protobuf = require(".."); +var long = require("long") + +tape.test("maps long key", function(test) { + var root = protobuf.Root.fromJSON({ + nested: { + Test: { + fields: { + foo: { + keyType: "uint64", + type: "uint64", + id: 1 + } + } + } + } + }); + + var Test = root.lookup("Test"); + var input = { + "1": new long(2, 0, true) + }; + var buffer = Test.encode({foo: input}).finish(); + var decoded = Test.decode(buffer); + test.deepEqual(decoded.foo, input, "should decode back to the original map"); + + var altInput = { + "1": "2" + }; + buffer = Test.encode({foo: altInput}).finish(); + decoded = Test.decode(buffer); + test.deepEqual(decoded.foo, input, "alt input should decode") + + test.end(); +});