ipfs / protons

Protocol Buffers for Node.js and the browser without eval
Other
32 stars 23 forks source link

Write buffer when Enum field value is 0 #79

Closed skysbird closed 1 year ago

skysbird commented 1 year ago

Something wrong when type filed value is RESERVE, like the proto below:

message HopMessage { enum Type { RESERVE = 0; CONNECT = 1; STATUS = 2; }

required Type type = 1;

optional Peer peer = 2; optional Reservation reservation = 3; optional Limit limit = 4;

optional Status status = 5; }

achingbrain commented 1 year ago

required is a proto2 keyword, it is not present in proto3 so is ignored.

If a field with no keyword has the default value (0 in the case of enums) no value is written onto the wire - please see the proto3 spec: https://protobuf.dev/programming-guides/proto3/

To write a default value on the wire with proto3 the field must have the optional keyword.

This is functioning as expected, though perhaps an error should be thrown if invalid keywords like required are encountered.