Skip to content

Commit 7cd2d28

Browse files
authored
Merge pull request #229 from Logofile/sync
Documentation change
2 parents b9be4af + 2d3c6dc commit 7cd2d28

File tree

7 files changed

+85
-44
lines changed

7 files changed

+85
-44
lines changed

content/_index.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ Objective-C, Python, and Ruby. With proto3, you can also work with PHP.
2424
## Example Implementation
2525

2626
```proto
27+
edition = "2023";
28+
2729
message Person {
28-
optional string name = 1;
29-
optional int32 id = 2;
30-
optional string email = 3;
30+
string name = 1;
31+
int32 id = 2;
32+
string email = 3;
3133
}
3234
```
3335

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
+++
2+
title = "Avoid Cargo Culting"
3+
weight = 90
4+
description = "Avoid using features where they are not needed."
5+
type = "docs"
6+
+++
7+
8+
Do not [cargo cult](http://go/cargocult-definition) settings in proto files. If
9+
you are creating a new proto file based on existing schema definitions, don't
10+
apply option settings except for those that you understand the need for.
11+
12+
## Best Practices Specific to Editions {#editions}
13+
14+
Avoid applying [editions features](/editions/features)
15+
except when they're actually necessary. Features in `.proto` files signal the
16+
use of either experimental future behaviors or deprecated past behaviors. Best
17+
practices for the latest edition will always be the default. New proto schema
18+
definition content should remain feature-free, except if you want to early-adopt
19+
a feature for future behavior that's being rolled out.
20+
21+
Copying-forward feature settings without understanding why they are set can lead
22+
to unexpected behaviors in your code.

content/editions/features.md

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ This topic provides an overview of the features that are included in Edition
99
2023. Each subsequent edition's features will be added to this topic. We
1010
announce new editions in [the News section](/news).
1111

12+
Before configuring feature settings in your new schema definition content, make
13+
sure you understand why you are using them. Avoid
14+
[cargo-culting](/best-practices/no-cargo-cults) with
15+
features.
16+
1217
## Prototiller {#prototiller}
1318

1419
Prototiller is a command-line tool that converts proto2 and proto3 definition

content/overview.md

+29-30
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ data on disk. Protocol buffer *messages* and *services* are described by
3131
engineer-authored `.proto` files. The following shows an example `message`:
3232

3333
```proto
34+
edition = "2023";
35+
3436
message Person {
35-
optional string name = 1;
36-
optional int32 id = 2;
37-
optional string email = 3;
37+
string name = 1;
38+
int32 id = 2;
39+
string email = 3;
3840
}
3941
```
4042

@@ -103,10 +105,8 @@ The following languages are supported by Google, but the projects' source code
103105
resides in GitHub repositories. The protoc compiler uses plugins for these
104106
languages:
105107

106-
<!-- mdformat off(mdformat adds a space between the ) and the {) -->
107108
* [Dart](https://github.com/google/protobuf.dart)
108109
* [Go](https://github.com/protocolbuffers/protobuf-go)
109-
<!-- mdformat on -->
110110

111111
Additional languages are not directly supported by Google, but rather by other
112112
GitHub projects. These languages are covered in
@@ -127,9 +127,9 @@ and
127127

128128
### Updating Proto Definitions Without Updating Code {#updating-defs}
129129

130-
Its standard for software products to be backward compatible, but it is less
130+
It's standard for software products to be backward compatible, but it is less
131131
common for them to be forward compatible. As long as you follow some
132-
[simple practices](/programming-guides/proto3/#updating)
132+
[simple practices](/programming-guides/proto3#updating)
133133
when updating `.proto` definitions, old code will read new messages without
134134
issues, ignoring any newly added fields. To the old code, fields that were
135135
deleted will have their default value, and deleted repeated fields will be
@@ -159,8 +159,8 @@ Protocol buffers do not fit all data. In particular:
159159
* Protocol buffer messages are less than maximally efficient in both size and
160160
speed for many scientific and engineering uses that involve large,
161161
multi-dimensional arrays of floating point numbers. For these applications,
162-
[FITS](https://en.wikipedia.org/wiki/FITS) and similar formats
163-
have less overhead.
162+
[FITS](https://en.wikipedia.org/wiki/FITS) and similar formats have less
163+
overhead.
164164
* Protocol buffers are not well supported in non-object-oriented languages
165165
popular in scientific computing, such as Fortran and IDL.
166166
* Protocol buffer messages don't inherently self-describe their data, but they
@@ -175,11 +175,9 @@ Protocol buffers do not fit all data. In particular:
175175

176176
Many projects use protocol buffers, including the following:
177177

178-
<!-- mdformat off(mdformat adds a space between the ) and the {) -->
179-
180178
+ [gRPC](https://grpc.io)
181179
+ [Google Cloud](https://cloud.google.com)
182-
+ [Envoy Proxy](https://www.envoyproxy.io) <!-- mdformat on -->
180+
+ [Envoy Proxy](https://www.envoyproxy.io)
183181

184182
## How do Protocol Buffers Work? {#work}
185183

@@ -197,9 +195,9 @@ earlier, this is a `.proto` definition:
197195

198196
```proto
199197
message Person {
200-
optional string name = 1;
201-
optional int32 id = 2;
202-
optional string email = 3;
198+
string name = 1;
199+
int32 id = 2;
200+
string email = 3;
203201
}
204202
```
205203

@@ -230,14 +228,14 @@ std::string email = john.email();
230228
231229
## Protocol Buffers Definition Syntax {#syntax}
232230
233-
When defining `.proto` files, you can specify that a field is either `optional`
234-
or `repeated` (proto2 and proto3) or leave it set to the default, implicit
235-
presence, in proto3. (The option to set a field to `required` is absent in
236-
proto3 and strongly discouraged in proto2. For more on this, see [Required Fields Considered Harmful](/programming-guides/required-considered-harmful.md).)
231+
When defining `.proto` files, you can specify cardinality (singular or
232+
repeated). In proto2 and proto3, you can also specify if the field is optional.
233+
In proto3, setting a field to optional
234+
[changes it from implicit presence to explicit presence](/programming-guides/field_presence).
237235
238-
After setting the optionality/repeatability of a field, you specify the data
239-
type. Protocol buffers support the usual primitive data types, such as integers,
240-
booleans, and floats. For the full list, see
236+
After setting the cardinality of a field, you specify the data type. Protocol
237+
buffers support the usual primitive data types, such as integers, booleans, and
238+
floats. For the full list, see
241239
[Scalar Value Types](/programming-guides/proto3#scalar).
242240
243241
A field can also be of:
@@ -249,16 +247,17 @@ A field can also be of:
249247
and at most one field will be set at the same time.
250248
* A `map` type, to add key-value pairs to your definition.
251249
252-
In proto2, messages can allow **extensions** to define fields outside of the
253-
message, itself. For example, the protobuf library's internal message schema
254-
allows extensions for custom, usage-specific options.
250+
Messages can allow **extensions** to define fields outside of the message,
251+
itself. For example, the protobuf library's internal message schema allows
252+
extensions for custom, usage-specific options.
255253
256254
For more information about the options available, see the language guide for
257-
[proto2](/programming-guides/proto2) or
258-
[proto3](/programming-guides/proto3).
255+
[proto2](/programming-guides/proto2),
256+
[proto3](/programming-guides/proto3), or
257+
[edition 2023](/programming-guides/editions).
259258
260-
After setting optionality and field type, you choose a name for the field.
261-
There are some things to keep in mind when setting field names:
259+
After setting cardinality and data type, you choose a name for the field. There
260+
are some things to keep in mind when setting field names:
262261
263262
* It can sometimes be difficult, or even impossible, to change field names
264263
after they've been used in production.
@@ -303,4 +302,4 @@ protobuf developers and users,
303302
## Additional Resources {#additional-resources}
304303
305304
* [Protocol Buffers GitHub](https://github.com/protocolbuffers/protobuf/)
306-
* [Codelabs](/getting-started/codelabs)
305+
* [Tutorials](https://protobuf.dev/getting-started/)

content/programming-guides/proto2.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ value for that field. The default values are type-specific:
676676
[generated code guide](/reference/) for your language
677677
for details.
678678
* For enums, the default value is the **first defined enum value**, which
679-
should be 0 (recommended for compatibility with proto3). See
679+
should be 0 (recommended for compatibility with open enums). See
680680
[Enum Default Value](#enum-default).
681681

682682
The default value for repeated fields is empty (generally an empty list in the
@@ -930,10 +930,11 @@ project and use fully qualified names for all imports.
930930
### Using proto3 Message Types {#proto3}
931931

932932
It's possible to import
933-
[proto3](/programming-guides/proto3) message types and
934-
use them in your proto2 messages, and vice versa. However, proto2 enums cannot
935-
be used directly in proto3 syntax (it's okay if an imported proto2 message uses
936-
them).
933+
[proto3](/programming-guides/proto3) and
934+
[edition 2023](/programming-guides/editions) message
935+
types and use them in your proto2 messages, and vice versa. However, proto2
936+
enums cannot be used directly in proto3 syntax (it's okay if an imported proto2
937+
message uses them).
937938

938939
## Nested Types {#nested}
939940

@@ -1857,11 +1858,11 @@ open source RPC system developed at Google. gRPC works particularly well with
18571858
protocol buffers and lets you generate the relevant RPC code directly from your
18581859
`.proto` files using a special protocol buffer compiler plugin. However, as
18591860
there are potential compatibility issues between clients and servers generated
1860-
with proto2 and proto3, we recommend that you use proto3 for defining gRPC
1861-
services. You can find out more about proto3 syntax in the
1862-
[Proto3 Language Guide](/programming-guides/proto3). If
1863-
you do want to use proto2 with gRPC, you need to use version 3.0.0 or higher of
1864-
the protocol buffers compiler and libraries.
1861+
with proto2 and proto3, we recommend that you use proto3 or edition 2023 for
1862+
defining gRPC services. You can find out more about proto3 syntax in the
1863+
[Proto3 Language Guide](/programming-guides/proto3) and
1864+
about edition 2023 in
1865+
[Edition 2023 Language Guide](/programming-guides/editions).
18651866
18661867
In addition to gRPC, there are also a number of ongoing third-party projects to
18671868
develop RPC implementations for Protocol Buffers. For a list of links to

content/programming-guides/proto3.md

+2
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ automatically generated class:
532532
</tr>
533533
<tr>
534534
<td>sint32</td>
535+
<td>int32_t</td>
535536
<td>int</td>
536537
<td>int</td>
537538
<td>int32</td>
@@ -543,6 +544,7 @@ automatically generated class:
543544
</tr>
544545
<tr>
545546
<td>sint64</td>
547+
<td>int64_t</td>
546548
<td>long</td>
547549
<td>int/long<sup>[4]</sup></td>
548550
<td>int64</td>

content/reference/protobuf/google.protobuf.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1240,12 +1240,22 @@ A Timestamp represents a point in time independent of any time zone or calendar,
12401240
represented as seconds and fractions of seconds at nanosecond resolution in UTC
12411241
Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends
12421242
the Gregorian calendar backwards to year one. It is encoded assuming all minutes
1243-
are 60 seconds long, i.e. leap seconds are \"smeared\" so that no leap second
1243+
are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
12441244
table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
12451245
9999-12-31T23:59:59.999999999Z. By restricting to that range, we ensure that we
12461246
can convert to and from RFC 3339 date strings. See
12471247
<https://www.ietf.org/rfc/rfc3339.txt>.
12481248

1249+
The Timestamp type is encoded as a string in the RFC 3339 format:
1250+
"`{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z`", where `{year}` is
1251+
always expressed using four digits while `{month}`, `{day}`, `{hour}`, `{min}`,
1252+
and `{sec}` are zero-padded to two digits each. The fractional seconds, which
1253+
can go up to 9 digits (that is, up to 1 nanosecond resolution), are optional.
1254+
The "Z" suffix indicates the timezone ("UTC"); the timezone is required. A
1255+
proto3 JSON serializer should always use UTC (as indicated by "Z") when printing
1256+
the Timestamp type and a proto3 JSON parser should be able to accept both UTC
1257+
and other timezones (as indicated by an offset).
1258+
12491259
Example 1: Compute Timestamp from POSIX `time()`.
12501260

12511261
```cpp

0 commit comments

Comments
 (0)