2019-08-06 go protocolbuffer
2019-08-06 本文已影响0人
cityhash123
message People {
enum PeopleName {
Alice = 100;
Bob = 101;
Cathy = 102;
}
optional PeopleName name = 1;
}
Go protobuf生成器将枚举名称映射到值(反之亦然).您可以使用此映射将字符串转换为枚举值
str := "Cathy"
value, ok := People_PeopleName_value[str]
if !ok {
panic("invalid enum value")
}
var people People
people.Name = People_PeopleName(value).Enum()