Skip to content

zero numerics on optional fields are not encoded #185

@dysonreturns

Description

@dysonreturns

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions