google / proto-lens

API for protocol buffers using modern Haskell language and library patterns.
https://google.github.io/proto-lens
BSD 3-Clause "New" or "Revised" License
467 stars 109 forks source link

Preserve unknown proto2 fields and enums #29

Open judah opened 8 years ago

judah commented 8 years ago

We should preserve unknown fields and enums in proto2 messages.

From the docs: https://developers.google.com/protocol-buffers/docs/proto

Similarly, messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing. However, the unknown fields are not discarded, and if the message is later serialized, the unknown fields are serialized along with it – so if the message is passed on to new code, the new fields are still available.

Also, enums with unknown values should be treated like unknown fields and preserved for reserialization. (Note that this behavior is proto2-only; #28 describes the desired behavior for proto3.)

judah commented 7 years ago

Update: as described in google/protobuf#272, the specification is changing to preserve unknown fields in proto3 as well as proto2. See also: https://docs.google.com/document/d/1KMRX-G91Aa-Y2FkEaHeeviLRRNblgIahbsk4wA14gRk/edit#heading=h.w8dtggryroj4

When we implement this behavior, we should follow the new spec.

judah commented 7 years ago

This has been mostly done for unknown fields (but not enums), in #129.

There are a couple remaining edge cases: