@@ -228,19 +228,39 @@ number in the future.
228228You should also reserve the field name to allow JSON and TextFormat encodings of
229229your message to continue to parse.
230230
231- ### Reserved Fields {#fieldreserved}
231+ <a id =" fieldreserved " ></a >
232+
233+ ### Reserved Field Numbers {#reserved-field-numbers}
232234
233235If you [ update] ( #updating ) a message type by entirely deleting a field, or
234236commenting it out, future developers can reuse the field number when making
235237their own updates to the type. This can cause severe issues, as described in
236- [ Consequences of Reusing Field Numbers] ( #consequences ) .
238+ [ Consequences of Reusing Field Numbers] ( #consequences ) . To make sure this
239+ doesn't happen, add your deleted field number to the ` reserved ` list.
240+
241+ The protoc compiler will generate error messages if any future developers try to
242+ use these reserved field numbers.
243+
244+ ``` proto
245+ message Foo {
246+ reserved 2, 15, 9 to 11;
247+ }
248+ ```
249+
250+ Reserved field number ranges are inclusive (` 9 to 11 ` is the same as `9, 10,
251+ 11`).
237252
238- To make sure this doesn't happen, add your deleted field number to the
239- ` reserved ` list. To make sure JSON and TextFormat instances of your message can
240- still be parsed, also add the deleted field name to a ` reserved ` list.
253+ #### Reserved Field Names {#reserved-field-names}
241254
242- The protocol buffer compiler will complain if any future developers try to use
243- these reserved field numbers or names.
255+ Reusing an old field name later is generally safe, except when using TextProto
256+ or JSON encodings where the field name is serialized. To avoid this risk, you
257+ can add the deleted field name to the ` reserved ` list.
258+
259+ Reserved names affect only the protoc compiler behavior and not runtime
260+ behavior, with one exception: TextProto implementations may discard unknown
261+ fields (without raising an error like with other unknown fields) with reserved
262+ names at parse time (only the C++ and Go implementations do so today). Runtime
263+ JSON parsing is not affected by reserved names.
244264
245265``` proto
246266message Foo {
@@ -249,9 +269,8 @@ message Foo {
249269}
250270```
251271
252- Reserved field number ranges are inclusive (` 9 to 11 ` is the same as `9, 10,
253- 11`). Note that you can't mix field names and field numbers in the same
254- ` reserved ` statement.
272+ Note that you can't mix field names and field numbers in the same ` reserved `
273+ statement.
255274
256275### What's Generated from Your ` .proto ` ? {#generated}
257276
0 commit comments