问题
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;
}
回答1:
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 entires 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
来源:https://stackoverflow.com/questions/41138001/protocol-buffers-3-enums-as-keys-in-a-map