Protobuf's encoding leans on three bit-level concepts. There's byte order, bit shifting, and bitwise OR. If you can already read x << 3 | y, skip ahead. If not, here's the short version.
Further Reading
- Endianness
Byte order in full: where little- and big-endian come from, and why the distinction matters the moment bytes leave one machine for another.
- Bit shifts
The shift operations behind the tag formula, including the arithmetic/logical distinction this page glosses over.
- Bitwise OR
How OR merges bit patterns, alongside the AND and XOR siblings that decoders lean on.
Next
Base-128 Varints
How Protobuf base-128 varints encode integers in as few bytes as possible: continuation bits, byte layout, and an interactive varint encoder.