Skip to content

Commit 05a8310

Browse files
authored
Merge pull request #157 from Logofile/main
Documentation updates
2 parents 08e0937 + 577c0c6 commit 05a8310

File tree

6 files changed

+278
-107
lines changed

6 files changed

+278
-107
lines changed

content/editions/features.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ overrides the message-scope QUUX setting.
5757
### `features.enum_type` {#enum_type}
5858

5959
This feature sets the behavior for how enum values that aren't contained within
60-
the defined set are handled.
60+
the defined set are handled. See
61+
[Enum Behavior](/programming-guides/enum) for more
62+
information on open and closed enums.
6163

6264
This feature doesn't impact proto3 files, so this section doesn't have a before
6365
and after of a proto3 file.

content/programming-guides/dos-donts.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,52 +109,40 @@ using macro constants such as "`NULL`," "`NAN`," and "`DOMAIN`" as enum values.
109109

110110
## **Do** Use Well-Known Types and Common Types {#well-known-common}
111111

112-
Embedding the following common, shared types is strongly encouraged. Do not use
113-
`int32 timestamp_seconds_since_epoch` or `int64 timeout_millis` in your code
112+
Using the following common, shared types is strongly encouraged. E.g., do not
113+
use `int32 timestamp_seconds_since_epoch` or `int64 timeout_millis` in your code
114114
when a perfectly suitable common type already exists!
115115

116-
<a id="well-known-types"></a>
116+
<a id="well-known-types"></a><a id="common-types"></a>
117117

118-
### Well-Known Types {#well-known}
119-
120-
* [duration](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/duration.proto)
118+
* [`duration`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/duration.proto)
121119
is a signed, fixed-length span of time (for example, 42s).
122-
* [timestamp](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto)
120+
* [`timestamp`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto)
123121
is a point in time independent of any time zone or calendar (for example,
124122
2017-01-15T01:30:15.01Z).
125-
* [field_mask](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/field_mask.proto)
126-
is a set of symbolic field paths (for example, f.b.d).
127-
128-
<a id="common-types"></a>
129-
130-
### Common Types {#common}
131-
132-
* [`Duration`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/duration.proto)
133-
is a signed, fixed-length span of time, such as 42s.
134-
* [`Timestamp`](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto)
135-
is a point in time independent of any time zone or calendar, such as
136-
2017-01-15T01:30:15.01Z.
137123
* [`interval`](https://github.com/googleapis/googleapis/blob/master/google/type/interval.proto)
138124
is a time interval independent of time zone or calendar (for example,
139125
2017-01-15T01:30:15.01Z - 2017-01-16T02:30:15.01Z).
140126
* [`date`](https://github.com/googleapis/googleapis/blob/master/google/type/date.proto)
141127
is a whole calendar date (for example, 2005-09-19).
128+
* [`month`](https://github.com/googleapis/googleapis/blob/master/google/type/month.proto)
129+
is a month of year (for example, April).
142130
* [`dayofweek`](https://github.com/googleapis/googleapis/blob/master/google/type/dayofweek.proto)
143131
is a day of week (for example, Monday).
144132
* [`timeofday`](https://github.com/googleapis/googleapis/blob/master/google/type/timeofday.proto)
145133
is a time of day (for example, 10:42:23).
146-
* [`latlng`](https://github.com/googleapis/googleapis/blob/master/google/type/latlng.proto)
147-
is a latitude/longitude pair (for example, 37.386051 latitude and
148-
-122.083855 longitude).
149-
* [`money`](https://github.com/googleapis/googleapis/blob/master/google/type/money.proto)
150-
is an amount of money with its currency type (for example, 42 USD).
134+
* [`field_mask`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/field_mask.proto)
135+
is a set of symbolic field paths (for example, f.b.d).
151136
* [`postal_address`](https://github.com/googleapis/googleapis/blob/master/google/type/postal_address.proto)
152137
is a postal address (for example, 1600 Amphitheatre Parkway Mountain View,
153138
CA 94043 USA).
139+
* [`money`](https://github.com/googleapis/googleapis/blob/master/google/type/money.proto)
140+
is an amount of money with its currency type (for example, 42 USD).
141+
* [`latlng`](https://github.com/googleapis/googleapis/blob/master/google/type/latlng.proto)
142+
is a latitude/longitude pair (for example, 37.386051 latitude and
143+
-122.083855 longitude).
154144
* [`color`](https://github.com/googleapis/googleapis/blob/master/google/type/color.proto)
155145
is a color in the RGBA color space.
156-
* [`month`](https://github.com/googleapis/googleapis/blob/master/google/type/month.proto)
157-
is a month of year (for example, April).
158146

159147
<a id="do-define-widely-used-message-types-in-separate-files"></a>
160148

content/programming-guides/proto2.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,39 @@ number in the future.
228228
You should also reserve the field name to allow JSON and TextFormat encodings of
229229
your message to continue to parse.
230230

231-
### Reserved Fields {#fieldreserved}
231+
<a id="fieldreserved"></a>
232+
233+
### Reserved Field Numbers {#reserved-field-numbers}
232234

233235
If you [update](#updating) a message type by entirely deleting a field, or
234236
commenting it out, future developers can reuse the field number when making
235237
their 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
246266
message 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

content/programming-guides/proto3.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,39 @@ the future.
205205
You should also reserve the field name to allow JSON and TextFormat encodings of
206206
your message to continue to parse.
207207

208-
### Reserved Fields {#fieldreserved}
208+
<a id="fieldreserved"></a>
209+
210+
#### Reserved Field Numbers {#reserved-field-numbers}
209211

210212
If you [update](#updating) a message type by entirely deleting a field, or
211213
commenting it out, future developers can reuse the field number when making
212214
their own updates to the type. This can cause severe issues, as described in
213-
[Consequences of Reusing Field Numbers](#consequences).
215+
[Consequences of Reusing Field Numbers](#consequences). To make sure this
216+
doesn't happen, add your deleted field number to the `reserved` list.
217+
218+
The protoc compiler will generate error messages if any future developers try to
219+
use these reserved field numbers.
220+
221+
```proto
222+
message Foo {
223+
reserved 2, 15, 9 to 11;
224+
}
225+
```
226+
227+
Reserved field number ranges are inclusive (`9 to 11` is the same as `9, 10,
228+
11`).
214229

215-
To make sure this doesn't happen, add your deleted field number to the
216-
`reserved` list. To make sure JSON and TextFormat instances of your message can
217-
still be parsed, also add the deleted field name to a `reserved` list.
230+
#### Reserved Field Names {#reserved-field-names}
218231

219-
The protocol buffer compiler will complain if any future developers try to use
220-
these reserved field numbers or names.
232+
Reusing an old field name later is generally safe, except when using TextProto
233+
or JSON encodings where the field name is serialized. To avoid this risk, you
234+
can add the deleted field name to the `reserved` list.
235+
236+
Reserved names affect only the protoc compiler behavior and not runtime
237+
behavior, with one exception: TextProto implementations may discard unknown
238+
fields (without raising an error like with other unknown fields) with reserved
239+
names at parse time (only the C++ and Go implementations do so today). Runtime
240+
JSON parsing is not affected by reserved names.
221241

222242
```proto
223243
message Foo {
@@ -226,9 +246,8 @@ message Foo {
226246
}
227247
```
228248

229-
Reserved field number ranges are inclusive (`9 to 11` is the same as `9, 10,
230-
11`). Note that you can't mix field names and field numbers in the same
231-
`reserved` statement.
249+
Note that you can't mix field names and field numbers in the same `reserved`
250+
statement.
232251

233252
### What's Generated from Your `.proto`? {#generated}
234253

content/reference/other.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ We recommend that all third-party code generators be written as plugins, as this
2525
allows all generators to provide a consistent interface and share a single
2626
parser implementation.
2727

28+
Plugins can be written in any programming language, but Google owned plugins are
29+
written in C++. If you are writing your own plugin you may find it easiest to
30+
use C++ for the plugin to be able to follow those examples and reuse utilities.
31+
2832
Additionally, plugins are able to insert code into the files generated by other
2933
code generators. See the comments about \"insertion points\" in `plugin.proto`
3034
for more on this. This could be used, for example, to write a plugin which

0 commit comments

Comments
 (0)