-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proto: Marshal message with oneof field does not produce correct field order #395
Comments
I'm not sure what you're asking about. I can explain the results based on https://developers.google.com/protocol-buffers/docs/encoding ... RequestUserCreate{UserUid: 123456} == 08c0c407 Request{Value: &Request_UserCreate{req}} == 0a0408c0c407 Request{Value: &Request_UserCreate{req}, Uid: 1} == 10010a0408c0c407 Please explain more what you're asking about? Thanks. |
in Java,the result is:
In the order of size of tag, it should be 0a0408c0c4071001, but the result is not the same as expected |
The order of the fields should not matter. You should be able to deserialize those bytes in Java or other language implementations regardless of the field order. |
Yes, i can deserialize those bytes in Java, but if i use the bytes to sign, the server check sign will be wrong. This may be a bug |
I guess the following does mention about field orders ... "While you can use field numbers in any order in a .proto, when a message is serialized its known fields should be written sequentially by field number, as in the provided C++, Java, and Python serialization code. This allows parsing code to use optimizations that rely on field numbers being in sequence. However, protocol buffer parsers must be able to parse fields in any order, as not all messages are created by simply serializing an object – for instance, it's sometimes useful to merge two messages by simply concatenating them." I'd probably would not use the serialized bytes to do any signing though. If there are unknown fields, it states ... "If a message has unknown fields, the current Java and C++ implementations write them in arbitrary order after the sequentially-ordered known fields." |
Thank you for your advice, The client and server versions are consistent, it will avoid using the unknown fields. |
I'm closing this for the following reasons:
|
proto file:
go source:
the results:
the uid tag is 2,why proto.Marshal the result is before userCreate ?
The text was updated successfully, but these errors were encountered: