Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming enum value in protobuf - backward compatibility

I have a protobuf:

enum Type {
        UNDEFINED = 0;
        SMALL = 1;
        MEDIUM = 2;
        BIG = 3;
}

The last value was changed (not by me):

enum Type {
        UNDEFINED = 0;
        SMALL = 1;
        MEDIUM = 2;
        VERY_BIG = 3;
}

What would be the implications of such change on my ability to parse protobuf messages (the ones containing BIG)? Does it differs between parsing binary encoded or text encoded messages?

What is the best practice to deprecate BIG and introduce VERY_BIG value?

like image 711
Vitali Melamud Avatar asked Jun 14 '18 12:06

Vitali Melamud


1 Answers

If you're using the binary protobuf format, then: no problems. Only the raw value is sent - as a varint, not as a name. Data that used to map to BIG will now show as VERY_BIG. You will not be able to tell between the two.

Changing the schema and re-running protoc might give you a few build errors until you fix the same changes in your own code, but protobuf itself won't care, or even notice.

If you're using the JSON format: you'd need to test it. I don't know enough about the JSON rules (I try to avoid the JSON output).

In general, renaming isn't a great choice. It would be better to add a new entry with a new unique value and simply mark the old one as deprecated, but note that you might still expect old values.

Since EnumValueOptions has a deprecated flag you should be able to use [deprecated=true] against the old value to mark it obsolete.

like image 147
Marc Gravell Avatar answered Sep 28 '22 09:09

Marc Gravell