-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Problem encoding map<string, struct> #547
Comments
Example of what I encode
Example of what I get in golang decode
|
Here is my golang decode
|
I added a test mostly identical to your use case which I'll commit later on but it didn't show any issues. Once the test is available, please take a look if I am doing something different. |
@dcodeIO did you add a test for golang ? |
Hmm, well, it would help if you could make a test case that produces a minimal buffer that's different, so that I can compare the two buffers by hand. One thing I could think of is that the go library does not preserve the order of the map keys, while the JS implementation does. Just a shot in the dark, of course. |
Let me comment back with a better test, code and output |
Golang test
Golang Output
Node test
Node Output
If you were to load the node binary output in golang you would get |
Seems that my shot in the dark hit something: Either the Go library encodes maps in a different order, or the interop layer causes this. The reason might be that the underlying map data type used in Go does not guarantee to retain order of keys - a lot of languages actually don't guarantee this with default data types for performance reasons - but JS's internals do this. You can test this theory by using different values, and finding a pair that serializes in declaration order. Edit: see |
If it was just keys being in different order i'd be okay. But the whole object is different as you can see. If you were to parse node binary output with the golang library, you don't even get the key "alpha" Notice the extra "2" in the node binary output ? Edit: notice this |
|
Please let me know if this commit fixes your issue! |
Thanks a lot @dcodeIO Going to tag my dependency with this commit hash. When do you make the release ? |
It's up as 6.1.1. |
This is the proto file
I made the struct like this
I am loading this file in golang but I don't get the same struct. Which is odd because this approach works fine for other data types. Worked for regular datatypes, string array, and well defined structs.
This leads me to believe that there is something wrong with map<> in the encoding ?
The text was updated successfully, but these errors were encountered: