With the help of the answer I linked to in the comments I was able to write the following proto file:
import "google/protobuf/descriptor.proto";
extend google.protobuf.EnumValueOptions {
DogMessage.DogBreed dogBreed = 51234;
}
message DogMessage {
enum DogBreed {
GERMAN_SHEPHERD = 0;
FRENCH_BULLDOG = 1;
}
enum Dog {
MAX = 0 [(dogBreed) = GERMAN_SHEPHERD];
SCOOTER = 1 [(dogBreed) = FRENCH_BULLDOG];
}
}
The value of dogBreed
is then accessible on the client side using getValueDescriptor.getOptions()
However I realized I actually don't need it in the end. I was trying to replicate exactly my data model class.That's because I come from a JSON serialization world with Jackson where you send and receive exactly your data model classes.
But since protobuf uses an intermediate representation class I might as well write the following:
message DogMessage {
string dogName = 0;
string dogBreed = 1;
}
And I'll be able to reconstruct my data model Enums based on those string values on the other side.
Thanks for looking into this
EDIT: Further realization: it doesn't matter what the Dog
enum is made of. As long as I transfer one of it's value (MAX, SCOOTER), I'll be able to reconstruct the enum fully, based on this single value.