-
Notifications
You must be signed in to change notification settings - Fork 382
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
Decode unknown enum values #233
Comments
Is there an easy solution/workaround to avoid this behaviour? Even just ignore the unknown enums? We just experienced this error recently in https://github.com/librespot-org/librespot where the enum added was not important but everyone was required to update anyway. |
As for temporary workaround I'd suggest patching your I'm currently working on proper fix. |
Current patch set: https://github.com/stepancheg/rust-protobuf/commits/unknown-enum-value Comments, suggestions are welcome! Especially since this change will be somewhat backward incompatible. |
In protobuf2 an unknown enum value should be ignored ( From https://developers.google.com/protocol-buffers/docs/proto#updating
I personally find this horrible, and |
@plietar thank you very much for pointing to this valuable piece of spec. I'm not sure what would be better. Seems like syntax=proto3 The question what to do with
So we need to choose between options (3) and (4). Anyway, |
This fix long standing issue of protobuf returning error when parsing unknown enum values. New behavior matches proto2 (even is code is generated for proto3). This is backward-incompatible change. Issue #233
I've created a patch which implement storing unknown values in unknown fields: #276 This is source-compatible change, but behavior is changed. I want to merge it into 1.4 branch and create a new version. This is somewhat dangerous change, so I'd appreciate code review. |
This fix long standing issue of protobuf returning error when parsing unknown enum values. New behavior matches proto2 (even is code is generated for proto3). This is backward-incompatible change. Issue #233
This fix long standing issue of protobuf returning error when parsing unknown enum values. New behavior matches proto2 (even is code is generated for proto3). This is backward-incompatible change. Issue #233
Merged that diff and released as 1.5.0. Keeping the issue open to implement |
Hi, Any progress for implement |
Could |
@hicqu could you describe your use case? Why do you check for unknown enum values in unknown fields? I mean, unset enum and unknown enum are usually the same for the most applications, and storing enums in unknown fields is usually needed only to a) not failing during parsing b) preserving during decoding/encoding. I'm asking to better understand what people need to make a proper decision. |
@hicqu I also think that storing enums in |
My use case is about compatibility. It won't be a problem if if enum_from_message == EnumType::DefaultValue {
// do special logic.
} to if enum_from_message == EnumType::DefaultValue &&
message.get_unknown_fields().get(proto_enum_field_id).is_none() {
// do special logic.
} It's hard to check all places have used |
How about represent the enum as
This way we can keep similar behavior as other languages' implementations and also follow proto3's open enum semantics while keeping the interface clean and neat. |
Protobuf in master now generates enum fields as It's not late to revert this change. |
Currently rust-protobuf results in error when decoding unknown enum values.
Protobuf 3 requires that message should preserve unknown enum values, not simply drop them.
Proposal
will be introduced in the protobuf library.
Generated fields will be of that type:
Getters and setters will work with enums as previously (e. g.
Color
).The text was updated successfully, but these errors were encountered: