'How to handle C# nullable Enum in protobuf

I have nullable enum in my code which I'm trying to define in my .proto file but when I generate the C# class the enum is not nullable. Here is my proto file

enum Foo {
   Bar = 0;
   Bat = 1;      
}

message FooBar {
  int32 Id = 1;
  optional Foo Foo = 2;
}

I've read about two possible solutions.

  1. Use oneof but this way I can't set the Bar to be 0
  2. Add Unknown = 0; but this is not backward compatible with the existing data where the 0 element has different meaning

Is there another options or it is not possible to make Nullable<Enum> as of now?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source