15

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;
}
Vivek Sinha
  • 1,161
  • 2
  • 12
  • 22

1 Answers1

22

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

Vivek Sinha
  • 1,161
  • 2
  • 12
  • 22