What's the preferred way to encode a "nullable" field in protobuf 2?
Protobuf 2 messages have a built-in notion of "nullable fields". The C++ interface contains methods has_xxx
and clear_xxx
to check if the field has been set and to unset the field, respectively.
This feature comes "for free" due to the way fields are encoded in message using "tags". An unset field is simply "not present" in the encoded message.
Proto 3 does not have this feature, instead setting any missing field to its default value.