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
Constructing map<int64, ...> using longHash as keys doesn't yield correct proto on the wire #1203
Comments
Note: I'm using typescript generated static code and it runs in NodeJs context (main process of Electron) |
the map implementation at the moment is just the javascript object, to be able to use typed keys, the implementation needs to be changed to use proper map: |
the proper map implementation might be a good idea, but it is a major change of type. old code will have to be migrated for this version upgrade. |
I'm not sure if the implementation of map or being able to use typed keys is really important here. The type of key in the problematic example is string, but what matters is that proto field is a map with int64 keys. For example, a workaround that I use now is to use decimal number in string as keys, e.g.
works correctly and I guess converting I imagine there should be some code in encode that will check for a case of strings with 8 characters and parse them with Long.hashToLong |
I am facing the same issue. Any idea when it will be resolved? Or, any other solution? |
same issue here, have to turn back to official impl |
Same here |
I fix it temporarily use patch-package,this my code diff --git a/node_modules/protobufjs/src/decoder.js b/node_modules/protobufjs/src/decoder.js
index 491dd30..cfaa927 100644
--- a/node_modules/protobufjs/src/decoder.js
+++ b/node_modules/protobufjs/src/decoder.js
@@ -72,7 +72,7 @@ function decoder(mtype) {
("}");
if (types.long[field.keyType] !== undefined) gen
- ("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
+ ("%s[util.Long.isLong(k)?k.toString():typeof k===\"object\"?util.longToHash(k):k]=value", ref);
else gen
("%s[k]=value", ref); |
Same issue here. The issue is opened at 2019.4, now is 2021.8 the issue is still not fixed? |
SzHeJason's patch fixed it for me, can #1669 be merged? this issue has been open for more that 3.5 years... |
protobuf.js version: 6.8.8 (fetched through grpc 1.20-pre1)
Long 'hash' keys are not interpreted correctly when constructing map<int64, Obj>
For messages like that
creating message with
creates seemingly valid object, prints out as
but after encoding and decoding it, the key is changed to 0:
prints
The text was updated successfully, but these errors were encountered: