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

Unable to pack int 64

Open SamuelZon258 opened this issue 4 years ago • 1 comments
trafficstars

Hello, when I packaged "number", I could not package "int64". After I checked the source code, I changed "Number.isSafeInteger(object)" to "object.toString().indexOf('.') <0" It is temporarily solved. Obviously this is not the best method, but it can temporarily solve my problem. If there is a better solution to identify ”int64“, I hope to inform, thanks

SamuelZon258 avatar Jun 17 '21 06:06 SamuelZon258

This is because there's no int64 in JavaScript. A number that Number.isSafeInteger() returns false is NOT a precise integer (or not a "safe" integer) so that you should not deal it as integers but instead it is a floating point number.

If you need larger integers than "safe" integers, you have to use bigint. There's no direct support for bigint right now, but you can easily handle it. Seel https://github.com/msgpack/msgpack-javascript#handling-bigint-with-extensioncodec for details.

gfx avatar Jun 18 '21 02:06 gfx