Correct behaviour when encountering an unexpected enum on the wire

108 views
Skip to first unread message

Marc Gravell

unread,
May 11, 2011, 5:47:55 PM5/11/11
to Protocol Buffers
I'm doing some code maintenance on my protobuf library, and I have
encountered a test that is... confusing me. So before I go crazy (/
crazier)... what should an implementation do if during deserialization
it gets an enum it doesn't recognise?

- to explode in sparks?
- to ignore the data?
- to brutally coerce the data to the unexpected value?
- other?

Thanks in advance

Marc

Jason Hsueh

unread,
May 11, 2011, 6:19:45 PM5/11/11
to Marc Gravell, Protocol Buffers
Ignore the data (sort of): The unknown value gets treated as an unknown field, leaving the enum field unset. In implementations that support propagation of unknown fields (non-lite C++, Java), the value is added to the UnknownFieldSet.

Implications:
- a sender may set a required enum field to a valid value, according to its defintion of the .proto. If the recipient doesn't know about that value, the message may fail to parse. It's best to avoid required enums
- by treating it as an unknown field, a message can be sent between two programs who understand a particular enum value through a middleman that doesn't, and there is no loss of data


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages