Introduction
Protocol Buffers (protobuf) is Google’s format for
structured data. It was created inside Google in early 2001 and released as open
source in July 2008. The fields of each kind of message are declared in a
.proto schema, and the protoc compiler turns the schema into
code that reads and writes the compact binary form described here, which the
documentation calls the wire format.
A file that holds one encoded message is usually named .pb; the Protocol
Buffers documentation recommends .binpb. The bytes do not say which schema
wrote them: there is no signature, no header and no type field, so what a file
is depends on the schema. Machine learning models, browser and operating
system settings files and many network messages are Protocol Buffers underneath.
This page is the format read without a schema: any well-formed message, shown by field number and wire type. Each kind of file that has its own schema, such as an ONNX model, has a different top-level message and so a different layout, and is documented as a separate format; they are listed under Formats built on Protocol Buffers. A later version of a schema that only adds fields stays the same format.
A .pb or .binpb file dropped on any page of this site opens
in the explorer. It tries the schema formats first; for any other message it shows
every field by number and wire type, reads each length-delimited value as a nested
message, text, packed numbers or bytes, and says why it chose that reading.
Structure
An encoded message is a run of fields and nothing else. It has no header, no magic number, no field count and no end marker: a message ends where its bytes end, at the end of the file or at the end of the length-delimited value that holds it. Each field is a tag followed by a value whose size the tag’s wire type gives. Field names are not stored; the schema maps each number to a name and a type.
0Tag a varint: the field number shifted left three bits, plus the wire type1 to 5 bytes…Value a varint, 8 or 4 fixed bytes, or a length and that many bytesvaries…Tag the next field, in any order1 to 5 bytes…Value and so on to the end of the messagevaries
| Wire type | Name | Value |
|---|---|---|
0 | VARINT | a varint: integers, booleans and enums |
1 | I64 | 8 bytes, little-endian: fixed64, sfixed64, double |
2 | LEN | a varint length, then that many bytes: strings, bytes, nested messages, packed repeated numbers |
3, 4 | SGROUP, EGROUP | the start and end of a group, a deprecated form of nested message |
5 | I32 | 4 bytes, little-endian: fixed32, sfixed32, float |
A complete file
This 254-byte file is a tensor from ONNX’s test data, an ONNX TensorProto. Read without the schema it is six fields; the schema gives them their names.
| Bytes | Field | Wire type | Value | Name in the schema |
|---|---|---|---|---|
08 03 | 1 | VARINT | 3 | dims |
08 04 | 1 | VARINT | 4 | dims |
08 05 | 1 | VARINT | 5 | dims |
10 01 | 2 | VARINT | 1 | data_type: FLOAT |
42 01 78 | 8 | LEN | 1 byte: x | name |
4A F0 01 78 CC E1 3F … | 9 | LEN | 240 bytes | raw_data: 60 floats, the first 78 CC E1 3F = 1.764052 |
The reference
- Varints and zigzag – how integers, tags and lengths are stored
- Wire types and tags – the tag, field numbers and fixed-width values
- Length-delimited and nested messages – strings, bytes, nested messages, and how the explorer tells them apart
- Packed repeated fields – lists of numbers in one field
- Groups – the deprecated nested message without a length
- Field order, merging and unknown fields – what readers do with repeats, gaps and fields they do not know
- How maps and oneof are encoded – map entries as messages, oneof as ordinary fields
- File conventions – extensions, several messages in a file, descriptor sets, text format and JSON
- Extensions and MessageSet – fields defined outside their message, and the old MessageSet layout
- Editions and features – the features that replace proto2 and proto3, with their defaults
- Descriptor sets – descriptor.proto field by field, custom options and edition defaults, and the messages protoc exchanges with its plugins
- ProtoJSON – the JSON form of each type and of the well-known types
Versions
The wire format has never changed: every release reads and writes the same bytes. What changed between releases is the schema language and its defaults, such as whether repeated numbers are packed.
| Date | Release | What changed for files |
|---|---|---|
| early 2001 | proto1 | The format is created inside Google; proto1 was never released. |
| 7 Jul 2008 | 2.0.0 | First public release (proto2), a rewrite of proto1. |
| 13 May 2009 | 2.1.0 | [packed = true]: repeated numbers in one LEN field. |
| 1 Dec 2014 | 3.0.0-alpha-1 | syntax = "proto3" introduced. |
| 25 May 2015 | 3.0.0-alpha-3 | proto3 repeated numbers packed by default. |
| 27 Jul 2016 | 3.0.0 | proto3 released. |
| 2022 | 21.x | New version numbering, announced on 6 May 2022. |
| May 2024 | 27.0 | Editions released (Edition 2023): features replace the proto2 and proto3 syntax; repeated numbers packed by default, groups written as message_encoding = DELIMITED. |
| 2025 | 32.x | Edition 2024: changes to the language and generated code only; its defaults are in the features table. |
| Q3 2026 (planned) | 36.x | Edition 2026, planned: naming and visibility rules, and limits on messages and enums. The documentation already lists its defaults, but says the latest released edition is 2024, and the announcement warns that some changes may not land. |
The month of 27.0 comes from its release notes and from a changelog dated 14 May 2024 for its third release candidate; the day is not confirmed. The Editions documentation carries defaults for Editions 2024 and 2026, and none of the news posts mentions a change to the wire format.
Telling it apart
A message has no signature, so the explorer goes by the name and the first bytes. A
file is taken as Protocol Buffers when its name ends .pb,
.binpb, .desc or .onnx, its first field reads cleanly (a tag with
field number 1 or more and wire type 0, 1, 2, 3 or 5, and a value that fits in the
file), and its first 512 bytes are not all printable text. That last check turns
down text files named .pb: PureBasic source, a Git LFS pointer left in
place of the real file, or a message in
text format.
The explorer then tries the schema formats in turn, each strict about field numbers and wire types. The parser for this page, tried last, checks only that the whole file reads as fields to the last byte: valid tags, values that fit, and every group closed by the matching end-group tag.
Formats built on Protocol Buffers
These formats are each one Protocol Buffers message of a known type. The explorer tries them in this order before reading a file without a schema.
- ONNX tensor (TensorProto) – one tensor, as in ONNX’s test data
- ONNX sequence or optional value – a list of tensors, a map, or a value that may be absent
- ONNX model (ModelProto) – a whole model: graph, operators and weights
- Descriptor set (FileDescriptorSet) – the output of
protoc --descriptor_set_out - protoc plugin request or response – a
CodeGeneratorRequestorCodeGeneratorResponse(compiler/plugin.proto), what protoc exchanges with a plugin - TensorFlow SavedModel (saved_model.pb) – meta graphs, signatures and functions
- TensorFlow GraphDef (frozen graph) – nodes, with the weights as constants
After those, the explorer tries a SavedModel
fingerprint.pb by its name and a
delimited stream of several
messages, before reading the file as one message.
Other formats wrap Protocol Buffers messages in a framing of their own, such as OpenStreetMap PBF, which stores blocks of map data as length-prefixed messages.
Not described
Known, not yet covered
- Reference and viewer: the protobuf text format, which is documented on protobuf.dev but treated here as out of scope (see files).
- Reference and viewer: a raw message without its schema can only
be shown by wire type and field number; field names and meanings need the
.protoor a descriptor set.
Links
Software
- protoc – Google’s schema compiler;
protoc --decode_raw < fileprints any message without a schema,--decode=Typewith one (Windows, macOS, Linux) - Protoscope – prints and writes messages in a readable notation, with or without the schema
- Buf – command-line tool for schemas;
buf convertturns messages into text or JSON and back - CyberChef – data tool whose Protobuf Decode operation reads a message without a schema (web browser)
Developers
- protobuf – Google’s compiler and runtimes (C++, Java, Python, C#, Objective-C, PHP, Ruby, Kotlin, Dart through plugins)
- google.golang.org/protobuf – the official Go runtime (Go)
- protobuf.js – Protocol Buffers for browsers and Node.js (JavaScript)
- Protobuf-ES – Buf’s runtime and code generator (TypeScript, JavaScript)
- prost – Protocol Buffers for Rust (Rust)
- nanopb – small implementation for microcontrollers (C)
- protobuf-inspector – reads messages without the schema, for reverse engineering (Python)
Reference
- Encoding – the Protocol Buffers documentation of the wire format
- Language guide (proto3) – the schema language, field numbers, maps and oneof
- Language guide (proto2) – the older schema language, with groups
- Techniques – streaming several messages, self-describing messages and file names
- Text format language specification – the readable text form
- ProtoJSON format – the mapping to JSON