msgpack-node icon indicating copy to clipboard operation
msgpack-node copied to clipboard

64-bit number encoding/decoding in msgpack does not work

Open pingyuusa opened this issue 7 years ago • 4 comments

Due to the limitation of javascript the way numbers are store, 64 bit integers can not represented correctly.

msgpack decodes a 64 bit number as ordinary javascript numeric type which is incorrect and looses precision.

n = "18446464814936021036" x = [ 0xcf, 0xff, 0xff, 0x02, 0x04, 0x00, 0x00, 0xd8, 0x2c ] a = msgpack.unpack(x) a == 1844646481493602000 // not equal to n

unittest for this is incorrect too.

Need an alternate way to encode/decode 64 bit numbers to/from msgpack format

pingyuusa avatar Jul 14 '16 15:07 pingyuusa

64-bit numbers should be mapped to BigInt

bin-y avatar Jun 18 '20 14:06 bin-y

ping @pgriess @godsflaw

bin-y avatar Jun 18 '20 15:06 bin-y

Yeah, this should be solved with one of the BigInt packages. I'm very busy, but would be happy to take a PR.

godsflaw avatar Jun 29 '20 20:06 godsflaw

hi, I did write some code to implement this for my own use. But my implemention used BigInt type directly and ignored backward compatibility. Due to the compatibility issue, I think it won't be a good PR, but it could be a reference if you need. Here is my commit https://github.com/bin-y/msgpack-node/commit/bccf8a0e62b8b9075a205c747f5850c3414dd313

bin-y avatar Jul 08 '20 11:07 bin-y