User-defined types
enum
You are certainly already familiar with enums in your favorite language, and they are pretty much the same in Protobuf. When we know all the possible values of a type, we use enums to create a lightweight representation of each value:
EBNF – Enum syntax
enumValueOption = optionName "=" constant enumField = ident "=" [ "-" ] intLit [ "[" enumValueOption { "," enumValueOption } "]" ]";" enumBody = "{" { option | enumField | reserved } "}" enum = "enum" ident enumBody
As such, an enum in Protobuf looks like the following:
enum PhoneType { PHONE_TYPE_MOBILE = 0; PHONE_TYPE_HOME = 1; //... }
You can see that we are adding the name of the enum
(in UPPER_SNAKE_CASE) as the prefix of each value, and then we have this magic number following the equal sign. The naming is purely done according to convention...