I want to declare an enum, but I want it to be of size "int8_t" explicitly. As per protbuf docs[1], the generated enum in c++ is a standard c++ enum without explicitly mentioning the underlying type.
i.e. A declaration like this:
enum Foo {
VALUE_A = 0;
VALUE_B = 5;
VALUE_C = 1234;
}
Would generate something like this:
enum Foo {
VALUE_A = 0;
VALUE_B = 5;
VALUE_C = 1234;
Foo_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min,
Foo_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max
}
Is there anyway I can force protobuf to generate the enum with the type explicitly mentioned in the definition? Something like this:
enum Foo : int8_t {
VALUE_A = 0;
VALUE_B = 5;
VALUE_C = 1234;
Foo_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min,
Foo_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max
}
Why do I need this?
I want to forward declare my proto enum, and forward declaration of enums need you to:
Mention the datatype (so that compiler can assume the size used by the object)
The declaration of the enum must mention the exact same type as the definition [2]
Any help would be much appreciated.
[1] https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#enum