1001Ferramentas
📡Dev

gRPC Reserved Fields Builder

Turn a comma-separated list of field numbers and ranges such as 1,3,5-7 into a ready-to-paste reserved clause for a Protocol Buffers message.

Cláusula proto

Reserving removed field numbers in Protocol Buffers

In Protocol Buffers, what identifies a field on the wire is the number, not the name. Removing a field and later reusing that number makes the new field receive the old one's bytes — no error, no warning, the wrong value in the right place. The reserved keyword exists to make that impossible: the compiler refuses any attempt to reuse a reserved number.

Enter the removed numbers or ranges and the page assembles the declaration. Ranges use a hyphen, and several items are comma-separated. It is worth reserving the field name too, in a separate declaration, in case someone recreates a field with the same name under a different number — which confuses whoever reads the schema without breaking the encoding.

The rule of thumb is reserving whenever you remove, even in an internal schema. The cost is one line; the cost of not doing it is a data bug that only appears once two schema versions coexist in production, and it is among the hardest to track down, because the value arrives intact and in the wrong field. Note too that numbers 19000 to 19999 are already reserved by the protocol itself.

Frequently asked questions

Do I need to reserve the name too?
The encoding does not use the name, so recreating a field with an old name under a new number corrupts no data. But it confuses readers of the schema and breaks tools serialising to JSON, where the name matters. Reserving both is the recommended practice, in separate declarations.
What is the difference between reserving and marking deprecated?
Reserving removes the field from the schema and forbids the number. Marking deprecated keeps the field and merely signals to code generators that it should not be used — the field is still serialised. Deprecated is for the transition; reserving is for after the removal.
Which numbers should I avoid?
The 19000 to 19999 range is reserved by the protocol and the compiler refuses it. Also worth remembering that numbers 1 to 15 take one byte less on the wire — they should be saved for the most frequent fields, not spent on a rare one.

Related Tools