Enums are not allowed to be used as keys in map. PaxType here is an enum and not allowed to be used as key.
enum PaxType {
ADULT = 0 ;
CHILD = 1 ;
INFANT = 2 ;
}
message FlightData {
map<PaxType, FareType> fareType = 1;
}
In HashMap, we can use Enum as well as any other object as a key.
enum is one of the composite datatypes of Protobuf. It translates to an enum in the languages that we use, for example, Java.
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
Protocol Buffer (Protobuf) provides two simpler options for dealing with values that might be of more than one type. The Any type can represent any known Protobuf message type. And you can use the oneof keyword to specify that only one of a range of fields can be set in any message.
This is disallowed because it doesn't play well with proto3 open enum semantics. For example, in Java, if you have a Map, the key can only be one of the defined values. If you happen to receive an enum key value from a remote client/server that's not in the defined value set, it can't be put in the Map. This limitation forces us to either drop map entries with unknown enum keys (which is against proto3 open enum semantics), or disallow enum as map keys all together.
for reference: https://groups.google.com/forum/#!topic/protobuf/ikeldBe60eI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With