Skip to content
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

handling big integers #44

Closed
sshutovskyi opened this issue Jun 27, 2016 · 4 comments
Closed

handling big integers #44

sshutovskyi opened this issue Jun 27, 2016 · 4 comments

Comments

@sshutovskyi
Copy link

As of now this library handles integers over 2^53 as numbers which causes them to loose precision. The safer way would be to convert them to strings or buffers. Do you plan to add this to this package? In our project we extend your library to handle varint64 in this way, do you need a pull request with the similar implementation?

@mourner
Copy link
Member

mourner commented Jun 28, 2016

I'm not sure... I would probably use something like https://github.com/indutny/bn.js to handle big numbers, but I wouldn't want to pull in such a big dependency for a rare use case like this. Perhaps we could do away with just mentioning this in docs and providing a JS workaround in a gist?

@mourner
Copy link
Member

mourner commented Aug 25, 2016

Out of scope for this library for now, keeping it simple.

@mourner mourner closed this as completed Aug 25, 2016
@rdominy
Copy link

rdominy commented May 8, 2019

Now that Node.js 10.4+ supports BigInt any chance of revisiting support for this? I'm working with a 3rd party service that unfortunately using int64 to send IDs which doesn't work well trying to stuff into a 32 bit JavaScript int.

@UlysseM
Copy link
Contributor

UlysseM commented Jun 10, 2020

In order to be backward compatible, it might be worth looking at:
https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/DescriptorProtos.FieldOptions.JSType

JS_NORMAL would be the current behavior.
JS_NUMBER would parse and return the number as a bigint.
JS_STRING would parse and return as a string

The way compiler would need to make calls to the new functions writeVarintFromBigint / writeVarintFromString / readVarintFromBigint / readVarintFromString.

writeVarintFromString and readVarintFromString could be implemented by calling the Bigint variant and doing a toString value of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants