Protobuf's encoding uses a few bit-level operations: byte order, bit shifting, and the bitwise operators OR, AND, and XOR. If you can already read x << 3 | y, skip ahead. If not, here's the short version.
A byte is eight bits. This chapter writes each byte as two hex digits, so 0a is the bits 00001010, and the lowest bit is the one on the right.
Further Reading
- Endianness
Little- and big-endian byte order, and why it matters when bytes move between machines.
- 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, along with the AND and XOR operations decoders also use.
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.