← All notes

Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields

Answer: Start the file with syntax = "proto3";, then define each message as typed fields, each with a unique field number. Never reuse a field number: when you delete a field, add its number (and name) to a reserved list.

Example

syntax = "proto3";

message SearchRequest {
  reserved 5, 9 to 11;
  reserved "old_field";
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
  Corpus corpus = 4;
  repeated string tags = 6;
}

enum Corpus {
  CORPUS_UNSPECIFIED = 0;
  CORPUS_WEB = 1;
}

Field numbers

Syntax and labels

Default values

When encoded bytes lack a field, reading it returns a type-specific default: the empty string for strings, empty bytes for bytes, false for bools, zero for numeric types, and the first defined enum value (which must be 0) for enums. Repeated and map fields default to empty. For message fields, the field is not set.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Protocol Buffers docs, Language Guide (proto 3); protocolbuffers/protocolbuffers.github.io (GitHub), proto3.md (source page). BSD-3-Clause (https://raw.githubusercontent.com/protocolbuffers/protocolbuffers.github.io/main/LICENSE). Copyright Google Inc. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Protocol Buffers docs, Language Guide (proto 3); protocolbuffers/protocolbuffers.github.io (GitHub), proto3.md (source page). BSD-3-Clause (https://raw.githubusercontent.com/protocolbuffers/protocolbuffers.github.io/main/LICENSE). Copyright Google Inc.

Cite this

Permanent ID: iil:note:qyejg4y7

iinventedlight. 2026. "Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields." iinventedlight Library, iil:note:qyejg4y7, version of 2026-11-18. https://iinventedlight.com/library/notes/protobuf-message-types/. License: CC-BY-4.0.

@misc{iil_note_qyejg4y7,
  author = {{iinventedlight}},
  title = {{Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/protobuf-message-types/},
  note = {Permanent ID iil:note:qyejg4y7. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/protobuf-message-types.md.