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

Dealing with big numbers #1013

Closed
LiBa001 opened this issue Dec 21, 2020 · 3 comments
Closed

Dealing with big numbers #1013

LiBa001 opened this issue Dec 21, 2020 · 3 comments

Comments

@LiBa001
Copy link

LiBa001 commented Dec 21, 2020

Dealing with big numbers with gRPC

This is about using big numbers with gRPC that overflow in Javascript and lead to corrupted values.

Some background on my problem

I have a gRPC API that uses Discord Snowflake IDs which are basically unsigned 64-bit integers. I know the Discord API docs already mention that they implement these IDs as strings to prevent overflows. I originally planned to only use my API with Python and Go, though, where this overflow for these values was not an issue, so I naively defined them as fixed64 in my proto files.
Now I wanted to build a little website around my service, which accesses the API via gRPC-web. Unfortunately, I now run into this exact issue of the IDs overflowing (at least that's what my very strong guess is where the problem seems to be) my service receiving false values. Passing them as strings into my proto messages doesn't get me any further either, since gRPC-web seems to convert them back to numbers, thus them overflowing again. I then tried to use BigInts, but that only lead to the internal conversion failing.

What I am hoping for

So I am not super familiar with Javascript and all it's quirks, but I wanted to ask if it might be possible for gRPC-web to either support the BigInt type or somehow handle numbers passed as strings differently, so that they don't get converted back and overflow. This is highly needed for services that use some bigger numbers, such as proto's int64, uint65, sint64, but mostly fixed64, since fixed64 is supposed to be used with values greater than 2^56 wich already overflow as normal Javascript numbers.

@stanley-cheung
Copy link
Collaborator

This is an issue for protobuf.

@LiBa001
Copy link
Author

LiBa001 commented Dec 22, 2020

Oh, you may be right. I'm not exactly sure where this is handled in the stack, sorry.

@LiBa001
Copy link
Author

LiBa001 commented Dec 22, 2020

Omg, nevermind, I guess I found the corresponding issue there, which has a solution that hopefully works: protocolbuffers/protobuf#3666 (comment)

Gonna try it out tomorrow. I don't get why this option isn't documented anywhere, though.
But okay, it wasn't related to this repo. My apologies.

@LiBa001 LiBa001 closed this as completed Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants