February 2020
Intermediate to advanced
404 pages
8h 42m
English
Enumerations (enum) provide the ordering of numbers for a given set of elements. The default order of values is from 0 to n. So, in a protocol buffer message, we can have an enumeration type. Let's look at an example of the enum:
syntax 'proto3'; message Schedule{ enum Days{ SUNDAY = 0; MONDAY = 1; TUESDAY = 2; WEDNESDAY = 3; THURSDAY = 4; FRIDAY = 5; SATURDAY = 6; }}
What if we have to assign the same values for the multiple enumeration members?
Protobuf3 has an option called allow_alias that we can use to assign two different members the same value, like so:
enum EnumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}
Here, STARTED and RUNNING both have a 1 tag. This means ...
Read now
Unlock full access