Understand encoding
In this section we’ll explore the way in which protobuf encodes each type of data. The goal is to understand why protobuf is such a big win in terms of bandwidth optimization.
The first thing to realize is that we’ll use different strategies with the data type that we want to encode. Once every field is binary encoded we’ll need to concatenate each one of them in the order that we specified in the tags of the .proto
file. That’s how the receiver will be able to decode every message. In addition to the field encoding there are different strategies to delimit where the next field begins. This allows .proto
files to evolve, adding more fields. If the receiver doesn’t know the tag, it can be ignored and the receiver can move on to the next tag.
Here is a list of all the encoding type strategies:
Strategy | Name | Types |
---|---|---|
0 | Varint | int32, int64, uint32, uint64, sint32, sint64, bool, enum |
1 | 64-bit | fixed64, sfixed64, double |
2 | Length... |