How to design for a future additional enum value in protocol buffers?

Yes, the best approach is to make the first value in the enum something like UNKNOWN = 0. Then old programs reading a protobuf with an enum value they don’t recognize will see it as UNKNOWN and hopefully they can handle that reasonably, eg by skipping that element.

If you want to do this you’ll also want to make the enum be optional not required.

required, generally, means “I’d rather the program just abort than handle something it doesn’t understand.”

Note that it must be the first value declared in the proto source – just being the zero value doesn’t make it the default.

Leave a Comment