-
Notifications
You must be signed in to change notification settings - Fork 184
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
Avoid encoding 0 values for proto3 fields #269
Comments
for more info, see google/protobuf.dart#269
for more info, see google/protobuf.dart#269
for more info, see google/protobuf.dart#269
Is this relating to the binary encoding? |
@sigmundch Not sure if it's protobuf standard since I need to add it mannualy after generating transaction.proto like below: While Libra use rust-protobuf 2.7.0 will skip 0, no byte at all
|
Ah - I think I get it now. We could do that either when encoding or in the setter... Is this issue blocking you, or is it a nice-to-have? |
@sigmundch thanks for the explanation, no rush here |
This is a somewhat blocking issue for me, for the following reason... Consider a trivial message with just an integer (or enum) field.
We can instantiate this with a zero field either by I would expect the default value handling to mean that messages are considered equal regardless of whether an int value is unset or set to zero. Perhaps this is somewhat different than the issue subject here, but fixing this issue (not serializing zero fields) would highlight the problem further by making an object with a zero field not survive an encoding roundtrip and still compare equally. Currently it does, but only because zero fields are sent as explicit zeroes. |
This is indeed a different issue. The issue in your case is this part:
I thought we had an issue for this already but I can't find it now. We should open an issue for this if we don't have one already. As far as I can see proto specs do not say that default values for optional fields must be omitted. Only proto3 JSON spec says that (see #592, #585). So labeling this is "perf" instead of "bug". |
The proto3 language guide says about default values:
It doesn't use the word "must" in capital letters or so, but I think it's pretty well established that this is how proto3 should work... |
Thanks for pointing that out, I had missed that. Marking this issue as bug. |
current behaviour:
when a enum field is set with zero-value, the value is encoded in the buffer
expected behaviour:
when a enum field is set with zero-value, the value is omitted in encoding
The text was updated successfully, but these errors were encountered: