How do enums work in Protocol Buffers and what compatibility rules apply to them?
Last updated
Enums are named integer constants encoded as varints. In proto3 the first value must be
0(conventionallyUNSPECIFIED) and is the default.Proto3 enums are open: unknown numbers from a newer sender are preserved through an older reader.
Adding values is safe, but never change or reuse an existing number. Renaming keeps wire compatibility but breaks source code.
- https://protobuf.dev/programming-guides/proto3/
- https://buf.build/blog/totw-3-enum-names-need-prefixes
- https://guidetofix.blog/protobuf-enum-best-practices
- https://buf.build/docs/best-practices/style-guide/
- https://buf.build/docs/breaking/rules/
- https://buf.build/blog/totw-6-dangers-of-enum-aliases
- https://prachub.com/resources/protobuf-compatibility-interview-questions-field-numbers-unknown-fields-and-json-boundaries