Proto3 is the current recommended version of the Protocol Buffers language. Compared to proto2, it simplifies the type system, removes required fields, and makes default values implicit rather than user-defined.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/protocolbuffers/protobuf/llms.txt
Use this file to discover all available pages before exploring further.
Scalar value types
Proto3 defines a fixed set of scalar types that map directly to primitive types in each target language.| Proto type | Default | Notes |
|---|---|---|
double | 0 | 64-bit IEEE 754 floating point |
float | 0 | 32-bit IEEE 754 floating point |
int32 | 0 | Variable-length encoding; inefficient for negative numbers |
int64 | 0 | Variable-length encoding; inefficient for negative numbers |
uint32 | 0 | Variable-length unsigned encoding |
uint64 | 0 | Variable-length unsigned encoding |
sint32 | 0 | ZigZag encoding; efficient for negative numbers |
sint64 | 0 | ZigZag encoding; efficient for negative numbers |
fixed32 | 0 | Always 4 bytes; more efficient than uint32 for values > 2²⁸ |
fixed64 | 0 | Always 8 bytes; more efficient than uint64 for values > 2⁵⁶ |
sfixed32 | 0 | Always 4 bytes, signed |
sfixed64 | 0 | Always 8 bytes, signed |
bool | false | |
string | "" | Must be UTF-8 encoded or 7-bit ASCII |
bytes | b"" | Arbitrary byte sequence |
Message fields and field numbers
Every field in a message has a type, a name, and a field number. Field numbers identify the field in the binary encoding and must be unique within a message.1 to 15 use one byte in the encoding (including the field number and wire type). Field numbers 16 to 2047 use two bytes. Reserve 1 to 15 for the most frequently populated fields.
Valid field number ranges:
1to536,870,911(2²⁹ − 1)19,000to19,999are reserved by the Protocol Buffers implementation and cannot be used
Field labels
Singular fields (no label)
In proto3, a field with no label is a singular field. It holds at most one value. If not set, it contains the type’s default value.Optional fields (explicit presence)
Adding theoptional keyword gives a field explicit presence — the generated API tracks whether the field was explicitly set, not just what its value is.
- C++
- Go
- Java
- Python
Repeated fields
Arepeated field can hold zero or more values, ordered. It maps to a list or array in generated code.
Map fields
Map fields are a shorthand for an associative container. The key type can be any integral or string type; the value can be any type except another map.repeated. The entry order is not guaranteed.
Map fields in the binary format are represented as a repeated field of an auto-generated entry message, so they are wire-compatible with that representation.
Oneof fields
Aoneof declares that at most one field from the group can be set at a time. Setting one field in a oneof automatically clears all others.
oneof fields support explicit presence — the API exposes which variant (if any) is currently set. repeated fields cannot appear inside a oneof.
Enumerations
Enums define a named set of integer constants. The first enumerator must have the value0, which serves as the default.
allow_alias = true:
int32 are not supported. Received unknown enum values are preserved as unknown fields and available via the unknown fields accessor.
Nested messages
Messages can nest other message and enum definitions. Nested types are referenced using dot notation from outside the enclosing message:Reserved fields and names
When you delete a field or rename it, you should mark the old field number and/or name as reserved. This prevents future authors from accidentally reusing them — which would cause silent incompatibilities.to: 9 to 11 reserves numbers 9, 10, and 11 inclusive. The keyword max can be used for the upper bound: 40 to max.
Default values in proto3
Unset fields return their type’s default value. You cannot specify custom defaults in proto3.| Type | Default |
|---|---|
| Numeric types | 0 |
bool | false |
string | Empty string |
bytes | Empty bytes |
| Enum | First defined value (0) |
| Message fields | Language-specific null / absent |
optional keyword for explicit presence tracking.
JSON mapping
Proto3 defines a canonical JSON encoding. The mapping from field names uses lowerCamelCase in JSON regardless of the proto field naming style.| Proto type | JSON encoding |
|---|---|
message | Object {} |
enum | String name or integer |
map<K, V> | Object {} |
repeated V | Array [] |
bool | true / false |
string | String |
bytes | Base64 string |
int32, sint32, sfixed32 | Number |
int64, sint64, sfixed64 | String (to avoid JS precision loss) |
float, double | Number; "NaN", "Infinity", "-Infinity" |
Services and RPC methods
- Proto definition
- Go generated stub
- Java generated stub