4 ms·
I had some problem like this using protobuf2 enums The way protobuf handles enums, it recommends having an "UNKNOWN" as value 0, as when deserializing from the
by Tyr42 6y ago
I had some problem like this using protobuf2 enums
The way protobuf handles enums, it recommends having an "UNKNOWN" as value 0, as when deserializing from the wire any unknown enum value gets turned into value 0.
So it's recommended to have something like
enum FailReason {
UNKNOWN_ERROR = 0,
ERROR_1 = 1,
ERROR_2 = 2,
etc
}
But someone long ago made the enum I was dealing with look like this
enum {
SUCCESS = 0,
ERROR_1 = 1,
ERROR_2 = 2,
etc.
}
But this means I can't easily add a new error case, as it'll get interpreted as a success unless I carefully roll out the change to the receiving servers first.
But if I wasn't dealing with a distributed system I would like to have exhaustive checking.
- onei 6y agoI don't think that's protobuf's fault, it's simply a side effect of the common pattern in C of using memset when you initialise structs. I don't think there's a really good way around it other than remembering to think like a C programmer every now and then. I guess one option is to replace the endpoints that use the enum, but that seems heavy handed if it's wide spread.