Skip to content
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

zero numerics on optional fields are not encoded #185

Open
dysonreturns opened this issue Feb 3, 2025 · 0 comments · May be fixed by #186
Open

zero numerics on optional fields are not encoded #185

dysonreturns opened this issue Feb 3, 2025 · 0 comments · May be fixed by #186

Comments

@dysonreturns
Copy link

dysonreturns commented Feb 3, 2025

Given a message with an optional int

syntax = "proto3";

message Takeout {
    // nil (unspecified), 0 (no cutlery), 1 (1 set of cutlery), etc.
    optional uint32 cutlery_needed = 1;
    // Other fields...
}

The official Google proto library encodes these values as such:

Takeout.new(cutlery_needed:0).to_proto
# => "\b\x00"
Takeout.new(cutlery_needed:nil).to_proto
# => ""

When protoboeuf encodes this message, then it should match the output above:

Takeout.new(cutlery_needed:0).to_proto
=> ""
Takeout.new(cutlery_needed:nil).to_proto
=> ""

Notice how the 0 (zero) value is considered being unset and isn't transmitted "\b\x00".
This currentl breaks cross-language compatibility between these two libs and therefore also backwards compat with proto2.

Not sure how much it's going to cost, but we need to check the @_bitmask instead of val != 0 in these cases for whether something is set or not.

@dysonreturns dysonreturns linked a pull request Feb 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant