-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int64 #2
Comments
under the 'encode' method, you see the following code. This doesn't work for ints over 32bits, probably because bit shift operators are meant for 32bit values (or so I've heard. I'm no expert). // Floating Point Anyway, if you comment that out, and add a Math.floor for safety, you can then use the following code to encode ints up to +- 2^53-1 as 64bit uints and 64bit ints. I have forked version at https://github.com/parnesen/msgpack-js that implements this, though it sacrifices support for floats, since I don't need them and I haven't sorted out a proper floating point test. var bytePositions = [ /** reads an unsigned int of max value 2^53-1 from a uint64 binary representation **/ /** reads an signed int of max/min value +- 2^53-1 from a big endian two's complement int64 binary representation **/ function writeUint53(value, buffer, offset) { buffer[offset] = 0x0; //most significant bit is always zero function writeInt53(value, buffer, offset) { function copyBytes(count, buffer, offset) { /** determines whether the given big endian, two's complement byte representation of a 64 bit integer is negative **/ /** negates the given big endian byte representation of a 64 bit integer by taking the two's complement **/ |
Hi,
Your code uses methods "writeUInt64BE" and "writeInt64BE" (with matching read methods) for the buffer object, but this is not part of the nodejs standard buffer object. I think your tests don't actually hit those lines of code because all int64 objects get treated as if they are doubles.
var a = Date.now();
console.log("using a bit operator");
console.log("%j is a double: %j", a, (a << 0) !== a);
console.log("using Math.floor");
console.log("%j is a double: %j", a, Math.floor(a) !== a);
I'm not sure of the correct work around for this since javascript doesn't really support uint64 out of the box...
Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: