Encoding By Number
Protocol Buffers, often called protobuf, is the default message format for gRPC. You define messages in a schema, and each field gets a small field number that identifies it on the wire.
How The Wire Format Works
The encoding is built around tags and lengths, not names.
- Each field is written as a tag plus a value, where the tag combines the field number and a type hint.
- Field names never appear on the wire, only their numbers.
- Integers use a variable length encoding so small numbers take fewer bytes.
- Fields with default values can be omitted entirely.
Why Numbers Matter For Evolution
Using numbers instead of names makes schemas easy to evolve safely.
- You may add new fields with new numbers without breaking old readers.
- Old code simply ignores unknown field numbers.
- You must never reuse a retired field number, or readers will misinterpret data.
This is why field numbers, not names, are the real contract. Renaming a field is harmless, but changing its number or type is a breaking change.
Key idea
Protobuf encodes each field as a numbered tag and value, so field numbers form the real contract and let schemas grow by adding fields while old readers safely ignore unknown numbers.