Using special keywords in Protobuf
Protobuf has a range of special keywords that we haven't covered so far. Some of them are only used on rare occasions. For example, you may have to use special keywords to make your proto files compatible with an older version of Protobuf. We will not cover those in this chapter.
There are also some other Protobuf features that are only useful in a very narrow range of circumstances, such as using extensions and defining custom options. These will not be covered either due to their limited usefulness.
However, there are also some keywords that are very useful and accessible. The most prominent of them are oneof
and option
. These are the keywords that we will focus on now.
How the oneof keyword can make communication more efficient
Inside the greet.proto
file, we will modify the BasicTypes
message
definition. First, we will replace the fields with the sequence numbers from 1
to 10
with the following:
oneof whole_number_field { ...