What are reserved fields and reserved numbers in a .proto file, and why should you never reuse a tag number?
Last updated
reservedblocks field numbers or names (e.g.reserved 2, 9 to 11;orreserved "email";) so the compiler errors if anyone reuses them after a field is deleted.Reusing a tag number is dangerous because old clients and stored data decode those bytes with the old meaning and type, causing silent data corruption instead of a clean error.
Reserve both: the number protects wire compatibility, and the name protects source and JSON compatibility.
- https://protobuf.dev/programming-guides/proto3/
- https://medium.com/@sanhdoan/protocol-buffers-the-importance-of-reserved-and-deprecated-fields-bbb8d7d3211d
- https://www.skillveris.com/interview-questions/grpc/why-is-reusing-a-protobuf-field-number-dangerous-and-how-do-you-prevent-it
- https://victoriametrics.com/blog/go-protobuf-basic/
- https://dev.to/leapcell/why-protobuf-should-dominate-the-data-format-ecosystem-4ddd