deeplay-io/nice-grpc

[nice-grpc-web] Big uint64s are not supported

Closed this issue · 4 comments

When receiving a message with big uint64:

Uncaught Error: Value is larger than Number.MAX_SAFE_INTEGER
    at longToNumber (task.ts:3335:11)
    at Object.decode (task.ts:1095:26)
    at Object.decode (task.ts:777:56)
    at Object.decode [as responseDeserialize] (task.ts:438:48)
    at responseType.deserializeBinary (index.ts:96:27)
    at grpc-web-client.umd.js:1:9605
    at Array.forEach (<anonymous>)
    at e3.onTransportChunk (grpc-web-client.umd.js:1:9508)
    at t3.onmessage (grpc-web-client.umd.js:1:23691)

uint64 fields should be handled as string fields. That way client-side code can work around them with libraries like js-big-decimal.

nice-grpc doesn't do serialization itself, instead it off-loads it to ts-proto.

There's a feature request for bigint support.

In the meantime, you can enable using Longs by following option: --ts_proto_opt=forceLong=Long. See https://github.com/stephenh/ts-proto#number-types

Unfortunately, this doesn't work with maps. For people with the same problem, here's a relevant issue – stephenh/ts-proto#717

protobufjs/protobuf.js#1745 (comment)

I've added this in my web application's entry file and it seems work fine.

Closing this since the issue stephenh/ts-proto#708 is resolved. Please fill free to reopen if you think that this is a mistake.