Enums
Enums help you to spare a lot of bytes in serialized messages, specially when the strings sent through the network are repetitive, such us status codes, error messages, etc. The serialized value will contain only the tag of the field instead of the whole value.
syntax
=
"proto2"
;
message
Film
{
enum
ProducerCompanies
{
UNKNOWN
=
0
;
WARNER_BROS
=
1
;
PARAMOUNT
=
2
;
NETFLIX
=
3
;
}
ProducerCompanies
Producer
=
1
[
default
=
UNKNOWN
];
}
Notice that the UNKNOWN
enum type is highly recommended when the Producer
set up in the code doesn’t exist in the list. When it doesn’t exist, it is automatically set to 0, to avoid future inconsistencies.