Skip to content

Commit c14731f

Browse files
authored
Merge pull request #242 from Logofile/sync
Documentation change
2 parents 13bf22c + 837e6a6 commit c14731f

File tree

12 files changed

+134
-36
lines changed

12 files changed

+134
-36
lines changed

content/best-practices/dos-donts.md

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ example, see
277277
You should also avoid using keywords in your file paths, as this can also cause
278278
problems.
279279

280+
## **Do** Use java_outer_classname {#java-outer-classname}
281+
282+
Every proto schema definition file should set option `java_outer_classname` to
283+
the `.proto` file name converted to TitleCase with the '.' removed. For example,
284+
the file `student_record_request.proto` should set:
285+
286+
```java
287+
option java_outer_classname = "StudentRecordRequestProto";
288+
```
289+
280290
## Appendix {#appendix}
281291

282292
### API Best Practices {#api-best-practices}

content/best-practices/no-cargo-cults.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ description = "Avoid using features where they are not needed."
55
type = "docs"
66
+++
77

8-
Do not [cargo cult](http://go/cargocult-definition) settings in proto files. If
8+
Do not
9+
[cargo cult](https://en.wikipedia.org/wiki/Cargo_cult_programming)
10+
settings in proto files. If \
911
you are creating a new proto file based on existing schema definitions, don't
1012
apply option settings except for those that you understand the need for.
1113

content/editions/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ description = "Topics related to the Protobuf Editions functionality."
55
type = "docs"
66
+++
77

8-
* [Protocol Buffers Overview](/editions/overview)
8+
* [Protobuf Editions Overview](/editions/overview)
99
* [Feature Settings for Editions](/editions/features)
1010
* [Implementing Editions Support](/editions/implementation)

content/editions/features.md

+69-11
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,57 @@ act like proto2 or proto3 files. For more information on how Editions and
2929
Features work together to set behavior, see
3030
[Protobuf Editions Overview](/editions/overview).
3131

32-
Each of the following sections has an entry for what scope the feature applies
33-
to. This can include file, enum, message, or field. The following sample shows a
34-
mock feature applied to each scope:
32+
<span id="cascading"> Feature settings apply at different levels:</span>
33+
34+
**File-level:** These settings apply to all elements (messages, fields, enums,
35+
and so on) that don't have an overriding setting.
36+
37+
**Non-nested:** Messages, enums, and services can override settings made at the
38+
file level. They apply to everything within them (message fields, enum values)
39+
that aren't overridden, but don't apply to other parallel messages and enums.
40+
41+
**Nested:** Oneofs, messages, and enums can override settings from the message
42+
they're nested in.
43+
44+
**Lowest-level:** Fields, extensions, enum values, extension ranges, and methods
45+
are the lowest level at which you can override settings.
46+
47+
Each of the following sections has a comment that states what scope the feature
48+
can be applied to. The following sample shows a mock feature applied to each
49+
scope:
3550

3651
```proto
3752
edition = "2023";
3853
39-
// File-scope definition
54+
// File-level scope definition
4055
option features.bar = BAZ;
4156
4257
enum Foo {
43-
// Enum-scope definition
58+
// Enum (non-nested scope) definition
4459
option features.bar = QUX;
4560
4661
A = 1;
4762
B = 2;
4863
}
4964
5065
message Corge {
51-
// Message-scope definition
66+
// Message (non-nested scope) definition
5267
option features.bar = QUUX;
5368
54-
// Field-scope definition
69+
message Garply {
70+
// Message (nested scope) definition
71+
option features.bar = WALDO;
72+
string id = 1;
73+
}
74+
75+
// Field (lowest-level scope) definition
5576
Foo A = 1 [features.bar = GRAULT];
5677
}
5778
```
5879

59-
In this example, the setting `GRAULT` in the field-scope feature definition
60-
overrides the message-scope QUUX setting.
80+
In this example, the setting "`GRAULT"` in the lowest-level scope feature
81+
definition overrides the non-nested-scope "`QUUX`" setting. And within the
82+
Garply message, "`WALDO`" overrides "`QUUX`."
6183

6284
### `features.enum_type` {#enum_type}
6385

@@ -83,6 +105,9 @@ and after of a proto3 file.
83105

84106
**Behavior in proto3:** `OPEN`
85107

108+
**Note:** Feature settings on different schema elements
109+
[have different scopes](#cascading).
110+
86111
The following code sample shows a proto2 file:
87112

88113
```proto
@@ -102,6 +127,7 @@ this:
102127
edition = "2023";
103128
104129
enum Foo {
130+
// Setting the enum_type feature overrides the default OPEN enum
105131
option features.enum_type = CLOSED;
106132
A = 2;
107133
B = 4;
@@ -129,7 +155,7 @@ whether a protobuf field has a value.
129155

130156
**Applicable to the following scopes:** File, Field
131157

132-
**Default value in the Edition 2023:** `EXPLICIT`
158+
**Default behavior in the Edition 2023:** `EXPLICIT`
133159

134160
**Behavior in proto2:** `EXPLICIT`
135161

@@ -138,6 +164,9 @@ which case it behaves like `EXPLICIT`. See
138164
[Presence in Proto3 APIs](/programming-guides/field_presence#presence-in-proto3-apis)
139165
for more information.
140166

167+
**Note:** Feature settings on different schema elements
168+
[have different scopes](#cascading).
169+
141170
The following code sample shows a proto2 file:
142171

143172
```proto
@@ -156,6 +185,7 @@ After running Prototiller, the equivalent code might look like this:
156185
edition = "2023";
157186
158187
message Foo {
188+
// Setting the field_presence feature retains the proto2 required behavior
159189
int32 x = 1 [features.field_presence = LEGACY_REQUIRED];
160190
int32 y = 2;
161191
repeated int32 z = 3;
@@ -178,10 +208,13 @@ After running Prototiller, the equivalent code might look like this:
178208

179209
```proto
180210
edition = "2023";
211+
// Setting the file-level field_presence feature matches the proto3 implicit default
181212
option features.field_presence = IMPLICIT;
182213
183214
message Bar {
184215
int32 x = 1;
216+
// Setting the field_presence here retains the explicit state that the proto3
217+
// field has because of the optional syntax
185218
int32 y = 2 [features.field_presence = EXPLICIT];
186219
repeated int32 z = 3;
187220
}
@@ -214,6 +247,9 @@ and after of a proto3 file. Editions behavior matches the behavior in proto3.
214247

215248
**Behavior in proto3:** `ALLOW`
216249

250+
**Note:** Feature settings on different schema elements
251+
[have different scopes](#cascading).
252+
217253
The following code sample shows a proto2 file:
218254

219255
```proto
@@ -230,7 +266,7 @@ After running Prototiller, the equivalent code might look like this:
230266

231267
```proto
232268
edition = "2023";
233-
features.json_format = LEGACY_BEST_EFFORT;
269+
option features.json_format = LEGACY_BEST_EFFORT;
234270
235271
message Foo {
236272
string bar = 1;
@@ -270,6 +306,9 @@ the following conditions are met:
270306

271307
**Behavior in proto3:** `LENGTH_PREFIXED`. Proto3 doesn't support `DELIMITED`.
272308

309+
**Note:** Feature settings on different schema elements
310+
[have different scopes](#cascading).
311+
273312
The following code sample shows a proto2 file:
274313

275314
```proto
@@ -318,6 +357,9 @@ for `repeated` fields has been migrated to in Editions.
318357

319358
**Behavior in proto3:** `PACKED`
320359

360+
**Note:** Feature settings on different schema elements
361+
[have different scopes](#cascading).
362+
321363
The following code sample shows a proto2 file:
322364

323365
```proto
@@ -389,6 +431,9 @@ and after of a proto3 file.
389431

390432
**Behavior in proto3:** `VERIFY`
391433

434+
**Note:** Feature settings on different schema elements
435+
[have different scopes](#cascading).
436+
392437
The following code sample shows a proto2 file:
393438

394439
```proto
@@ -441,6 +486,9 @@ before and after of a proto3 file.
441486

442487
**Behavior in proto3:** `false`
443488

489+
**Note:** Feature settings on different schema elements
490+
[have different scopes](#cascading).
491+
444492
The following code sample shows a proto2 file:
445493

446494
```proto
@@ -495,6 +543,9 @@ specified on a field, but not both.
495543

496544
**Behavior in proto3:** `STRING`
497545

546+
**Note:** Feature settings on different schema elements
547+
[have different scopes](#cascading).
548+
498549
The following code sample shows a proto2 file:
499550

500551
```proto
@@ -568,6 +619,9 @@ before and after of a proto3 file.
568619

569620
**Behavior in proto3:** `DEFAULT`
570621

622+
**Note:** Feature settings on different schema elements
623+
[have different scopes](#cascading).
624+
571625
The following code sample shows a proto2 file:
572626

573627
```proto
@@ -592,6 +646,7 @@ option features.utf8_validation = NONE;
592646
option features.(pb.java).utf8_validation = VERIFY;
593647
message MyMessage {
594648
string foo = 1;
649+
string bar = 2;
595650
}
596651
```
597652

@@ -618,6 +673,9 @@ files.
618673

619674
**Behavior in proto3:** `false`
620675

676+
**Note:** Feature settings on different schema elements
677+
[have different scopes](#cascading).
678+
621679
## Preserving proto2 or proto3 Behavior {#preserving}
622680

623681
You may want to move to the editions format but not deal with updates to the way

content/includes/version-tables.css

+7-7
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,36 @@ table.version-chart td.active {
9595
/* latest release column */
9696
/*
9797
* How to advance the selection of the latest release:
98-
* Replace class 'y24q4' in the following selectors with 'y25q1' (the class
98+
* Replace class 'y25q1' in the following selectors with 'y25q2' (the class
9999
* referring to the quarter of the next release). Please also update this
100100
* instruction as a courtesy to the next maintainer.
101101
*/
102102

103103
/* visually replace 'yyQq' heading with string 'Latest' */
104-
table.version-chart th.y24q4 span {
104+
table.version-chart th.y25q1 span {
105105
display: none;
106106
}
107-
table.version-chart th.y24q4::after {
107+
table.version-chart th.y25q1::after {
108108
content: "Latest"
109109
}
110110

111111
/* draw a focus rectangle around the latest release column */
112-
table.version-chart th.y24q4 {
112+
table.version-chart th.y25q1 {
113113
border-top: 2px solid #e06666 !important;
114114
border-left: 2px solid #e06666 !important;
115115
border-right: 2px solid #e06666 !important;
116116
}
117-
table.version-chart td.y24q4 {
117+
table.version-chart td.y25q1 {
118118
font-weight: bold;
119119
border-left: 2px solid #e06666 !important;
120120
border-right: 2px solid #e06666 !important;
121121
}
122-
table.version-chart tr:last-child td.y24q4 {
122+
table.version-chart tr:last-child td.y25q1 {
123123
border-bottom: 2px solid #e06666 !important;
124124
}
125125

126126
/* future release columns */
127-
table.version-chart td:not(:has(~ .y24q4)):not(.y24q4) {
127+
table.version-chart td:not(:has(~ .y25q1)):not(.y25q1) {
128128
font-style: italic;
129129
}
130130

content/programming-guides/extension_declarations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ declarations in C++, you can declare the field type, field name, and cardinality
4545
containing the full extension definition:
4646

4747
```proto
48-
syntax = "proto2";
48+
edition = "2023";
4949
5050
message Foo {
5151
extensions 4 to 1000 [
@@ -108,7 +108,7 @@ This `reserved` tag is separate from the reserved keyword for regular fields and
108108
**does not require breaking up the extension range**.
109109

110110
```proto {highlight="context:reserved"}
111-
syntax = "proto2";
111+
edition = "2023";
112112
113113
message Foo {
114114
extensions 4 to 1000 [

content/programming-guides/json.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ topic.
2121

2222
When parsing JSON-encoded data into a protocol buffer, if a value is missing or
2323
if its value is `null`, it will be interpreted as the corresponding
24-
[default value](/programming-guides/editions#default).
24+
[default value](/programming-guides/editions#default). Multiple values for
25+
singular fields (using duplicate or equivalent JSON keys) are accepted and the
26+
last value is retained, as with binary format parsing. Note that not all
27+
protobuf JSON parser implementations are conformant, and some nonconformant
28+
implementations may reject duplicate keys instead.
2529

2630
When generating JSON-encoded output from a protocol buffer, if a protobuf field
2731
has the default value and if the field doesn't support field presence, it will

content/programming-guides/style.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ later used in a language where names are transformed to TitleCase where they
7979
collide.
8080

8181
When applied, this style rule means that you should use `XYZ2` or `XYZ_V2`
82-
rather than `XYZ_2`.
82+
rather than `XYZ_2` or `XYZ_2V`.
8383

8484
## Packages {#packages}
8585

@@ -198,7 +198,7 @@ For more service-related guidance, see
198198
and
199199
[Don't Include Primitive Types in a Top-level Request or Response Proto](/programming-guides/api#dont-include-primitive-types)
200200
in the API Best Practices topic, and
201-
[Define Messages in Separate Files](/best-practices/dos-donts#separate-files)
201+
[Define Message Types in Separate Files](/best-practices/dos-donts#separate-files)
202202
in Proto Best Practices.
203203

204204
## Things to Avoid {#avoid}

content/reference/java/java-generated.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,10 @@ class.
348348

349349
For message types, `setFoo()` also accepts an instance of the message's builder
350350
type as the parameter. This is just a shortcut which is equivalent to calling
351-
`.build()` on the builder and passing the result to the method.
351+
`.build()` on the builder and passing the result to the method. Further
352+
modifying the sub-builder passed to `setFoo` will **not** be reflected in the
353+
message class's builder. The message class's builder "takes ownership" of the
354+
sub-message.
352355

353356
If the field is not set, `getFoo()` will return a Foo instance with none of its
354357
fields set (possibly the instance returned by `Foo.getDefaultInstance()`).

content/reference/ruby/ruby-generated.md

+16
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,22 @@ int_repeatedfield.clear
274274
raise unless int_repeatedfield.empty?
275275
```
276276

277+
For repeated fields that contain messages, the constructor for
278+
`Google::Protobuf::RepeatedField` supports a variant with three arguments:
279+
`:message`, the class of the submessage, and the values to set:
280+
281+
```ruby
282+
first_message = MySubMessage.new(:foo => 42)
283+
second_message = MySubMessage.new(:foo => 79)
284+
285+
repeated_field = Google::Protobuf::RepeatedField.new(
286+
:message,
287+
MySubMessage,
288+
[first_message, second_message]
289+
)
290+
message.sub_message_repeated_field = repeated_field
291+
```
292+
277293
The `RepeatedField` type supports all of the same methods as a regular Ruby
278294
`Array`. You can convert it to a regular Ruby Array with `repeated_field.to_a`.
279295

content/support/migration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ with Abseil and STL. Notably, we've replaced the `MapPair` class with an alias
810810
to `std::pair`. This should be transparent for most users, but if you were using
811811
the class directly you may need to update your code.
812812

813-
### New JSON Parser {:#json-parser}
813+
### New JSON Parser {#json-parser}
814814

815815
Source of changes: [PR #10729](https://github.com/protocolbuffers/protobuf/pull/10729)
816816

0 commit comments

Comments
 (0)