Skip to content

Commit e7db7a6

Browse files
Protocol Buffer TeamLogofile
authored andcommitted
This change includes the following:
* Restructures the landing page (_index.md) to simplify the layout and bring the table of contents to the left side * Removes the `optional` keyword from examples in the editions/features.md topic * In /editions/overview.md: * Clarifies that 2023 is the latest released edition * Adds missing `package` syntax from proto examples * Adds a reserved keyword to the proto examples to show the syntax difference between proto2/proto3 and editions * Corrects syntax for enums in proto examples * Corrects the example from the `list_people` command’s unit tests in getting-started/gotutorial.md * Replaces an outdated link to OKRs with a link to codelabs in /overview.md * Adds information about `ruby_package` to /programming-guides/dos-donts.md * Corrects misspellings in several topics * Reorganizes the content in the presence table in /programming-guides/field_presence.md * Corrects instances of `[[]` that should have been `[` throughout C++ API documentation * Minor text changes in /cpp/arenas.md * Removes some outdated references to `has_foo()` being proto2-only in /cpp/cpp-generated.md * Adds information about `ruby_package` to /reference/ruby/ruby-generated.md * Removes reference to cross-domain mixing of protobuf gencode and runtime from the external docs, since it applies only internally PiperOrigin-RevId: 644492325 Change-Id: I651afbc2d6049818a1b579b4d0e779779cb06c57
1 parent 05a8310 commit e7db7a6

30 files changed

+153
-166
lines changed

content/_index.md

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ type = "docs"
77
no_list = "true"
88
+++
99

10-
<!--* css: "//depot/includes/suppress-nav.css" *-->
10+
## What Are Protocol Buffers?
1111

12-
<style>
13-
.row .highlight {
14-
margin-top: 2rem;
15-
margin-right: 0;
16-
margin-bottom: 0;
17-
margin-left: 0;
18-
padding: 0;
19-
}
20-
</style>
12+
Protocol buffers are Google's language-neutral, platform-neutral, extensible
13+
mechanism for serializing structured data – think XML, but smaller, faster, and
14+
simpler. You define how you want your data to be structured once, then you can
15+
use special generated source code to easily write and read your structured data
16+
to and from a variety of data streams and using a variety of languages.
17+
18+
## Pick Your Favorite Language
19+
20+
Protocol buffers support generated code in C++, C#, Dart, Go, Java,
21+
Kotlin,
22+
Objective-C, Python, and Ruby. With proto3, you can also work with PHP.
2123

22-
<div class="row">
23-
<div class="col-md">
24+
## Example Implementation
2425

2526
```proto
2627
message Person {
@@ -30,9 +31,7 @@ message Person {
3031
}
3132
```
3233

33-
<p class="caption">A proto definition.</>
34-
</div>
35-
<div class="col-md">
34+
**Figure 1.** A proto definition.
3635

3736
```java
3837
// Java code
@@ -43,12 +42,9 @@ Person john = Person.newBuilder()
4342
.build();
4443
output = new FileOutputStream(args[0]);
4544
john.writeTo(output);
46-
4745
```
4846

49-
<p class="caption">Using a generated class to persist data.</p>
50-
</div>
51-
<div class="col-md">
47+
**Figure 2.** Using a generated class to persist data.
5248

5349
```cpp
5450
// C++ code
@@ -59,34 +55,9 @@ john.ParseFromIstream(&input);
5955
id = john.id();
6056
name = john.name();
6157
email = john.email();
62-
6358
```
6459
65-
<p class="caption">Using a generated class to parse persisted data.</p>
66-
</div>
67-
</div>
68-
<div class="row">
69-
<div class="col-md">
70-
71-
## What Are Protocol Buffers?
72-
73-
Protocol buffers are Google's language-neutral, platform-neutral, extensible
74-
mechanism for serializing structured data – think XML, but smaller, faster, and
75-
simpler. You define how you want your data to be structured once, then you can
76-
use special generated source code to easily write and read your structured data
77-
to and from a variety of data streams and using a variety of languages.
78-
79-
</div>
80-
<div class="col-md">
81-
82-
## Pick Your Favorite Language
83-
84-
Protocol buffers support generated code in C++, C#, Dart, Go, Java,
85-
Kotlin,
86-
Objective-C, Python, and Ruby. With proto3, you can also work with PHP.
87-
88-
</div>
89-
<div class="col-md">
60+
**Figure 3.** Using a generated class to parse persisted data.
9061
9162
## How Do I Start?
9263
@@ -106,6 +77,3 @@ Objective-C, Python, and Ruby. With proto3, you can also work with PHP.
10677
chosen language.
10778
</li>
10879
</ol>
109-
110-
</div>
111-
</div>

content/editions/features.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ edition = "2023";
285285
286286
message Foo {
287287
message Bar {
288-
optional int32 x = 1;
288+
int32 x = 1;
289289
repeated int32 y = 2;
290290
}
291291
Bar bar = 1 [features.message_encoding = DELIMITED];
@@ -509,8 +509,8 @@ edition = "2023";
509509
import "google/protobuf/cpp_features.proto";
510510
511511
message Foo {
512-
optional string bar = 6;
513-
optional string baz = 7 [features.(pb.cpp).string_type = CORD];
512+
string bar = 6;
513+
string baz = 7 [features.(pb.cpp).string_type = CORD];
514514
}
515515
```
516516

content/editions/overview.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type = "docs"
99
Protobuf Editions replace the proto2 and proto3 designations that we have used
1010
for Protocol Buffers. Instead of adding `syntax = "proto2"` or `syntax =
1111
"proto3"` at the top of proto definition files, you use an edition number, such
12-
as `edition = "2024"`, to specify the default behaviors your file will have.
12+
as `edition = "2023"`, to specify the default behaviors your file will have.
1313
Editions enable the language to evolve incrementally over time.
1414

1515
Instead of the hardcoded behaviors that older versions have had, editions
@@ -22,6 +22,8 @@ the default behavior for the edition you've selected. You can also override your
2222
overrides. The [section later in this topic on lexical scoping](#scoping) goes
2323
into more detail on that.
2424

25+
*The latest released edition is 2023.*
26+
2527
## Lifecycle of a Feature {#lifecycles}
2628

2729
Editions provide the fundamental increments for the lifecycle of a feature.
@@ -93,6 +95,8 @@ Prototiller tool to change the definition files to use Protobuf Editions syntax.
9395
// proto2 file
9496
syntax = "proto2";
9597
98+
package com.example;
99+
96100
message Player {
97101
// in proto2, optional fields have explicit presence
98102
optional string name = 1;
@@ -110,6 +114,8 @@ message Player {
110114
111115
// in proto2 enums are closed
112116
optional Handed handed = 4;
117+
118+
reserved "gender";
113119
}
114120
```
115121

@@ -119,6 +125,8 @@ message Player {
119125
// Edition version of proto2 file
120126
edition = "2023";
121127
128+
package com.example;
129+
122130
message Player {
123131
// fields have explicit presence, so no explicit setting needed
124132
string name = 1;
@@ -137,6 +145,8 @@ message Player {
137145
}
138146
139147
Handed handed = 4;
148+
149+
reserved gender;
140150
}
141151
```
142152

@@ -155,6 +165,8 @@ Prototiller tool to change the definition files to use Protobuf Editions syntax.
155165
// proto3 file
156166
syntax = "proto3";
157167
168+
package com.example;
169+
158170
message Player {
159171
// in proto3, optional fields have explicit presence
160172
optional string name = 1;
@@ -172,6 +184,8 @@ message Player {
172184
173185
// in proto3 enums are open
174186
optional Handed handed = 4;
187+
188+
reserved "gender";
175189
}
176190
```
177191

@@ -181,6 +195,8 @@ message Player {
181195
// Editions version of proto3 file
182196
edition = "2023";
183197
198+
package com.example;
199+
184200
message Player {
185201
// fields have explicit presence, so no explicit setting needed
186202
string name = 1;
@@ -197,6 +213,8 @@ message Player {
197213
}
198214
199215
Handed handed = 4;
216+
217+
reserved gender;
200218
}
201219
```
202220

@@ -229,16 +247,16 @@ message Person {
229247
int32 id = 2 [features.presence = IMPLICIT];
230248
231249
enum Pay_Type {
232-
PAY_TYPE_UNSPECIFIED = 1,
233-
PAY_TYPE_SALARY = 2,
234-
PAY_TYPE_HOURLY = 3
250+
PAY_TYPE_UNSPECIFIED = 1;
251+
PAY_TYPE_SALARY = 2;
252+
PAY_TYPE_HOURLY = 3;
235253
}
236254
237255
enum Employment {
238256
option features.enum_type = OPEN;
239-
EMPLOYMENT_UNSPECIFIED = 0,
240-
EMPLOYMENT_FULLTIME = 1,
241-
EMPLOYMENT_PARTTIME = 2,
257+
EMPLOYMENT_UNSPECIFIED = 0;
258+
EMPLOYMENT_FULLTIME = 1;
259+
EMPLOYMENT_PARTTIME = 2;
242260
}
243261
Employment employment = 4;
244262
}
@@ -270,9 +288,9 @@ definition files, and vice versa:
270288
syntax = "proto2";
271289
272290
enum Employment {
273-
EMPLOYMENT_UNSPECIFIED = 0,
274-
EMPLOYMENT_FULLTIME = 1,
275-
EMPLOYMENT_PARTTIME = 2,
291+
EMPLOYMENT_UNSPECIFIED = 0;
292+
EMPLOYMENT_FULLTIME = 1;
293+
EMPLOYMENT_PARTTIME = 2;
276294
}
277295
```
278296

content/getting-started/gotutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ p := pb.Person{
232232
Name: "John Doe",
233233
234234
Phones: []*pb.Person_PhoneNumber{
235-
{Number: "555-4321", Type: pb.Person_PHONE_TYPE_HOME},
235+
{Number: "555-4321", Type: pb.PhoneType_PHONE_TYPE_HOME},
236236
},
237237
}
238238
```

content/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,4 @@ protobuf developers and users,
305305
## Additional Resources {#additional-resources}
306306
307307
* [Protocol Buffers GitHub](https://github.com/protocolbuffers/protobuf/)
308+
* [Codelabs](/getting-started/codelabs)

content/programming-guides/dos-donts.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ For example:
196196
https://google.github.io/styleguide/cppguide.html#Namespace_Names.
197197
If these style guides conflict, use `java_package` for Java.
198198

199+
* `ruby_package` should be in the form `Foo::Bar::Baz` rather than
200+
`Foo.Bar.Baz`.
201+
199202
<a id="never-use-text-format-messages-for-interchange"></a>
200203

201204
## **Don't** use Text Format Messages for Interchange {#text-format-interchange}

content/programming-guides/enum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ question:
4949

5050
## Implications of *Closed* Enums
5151

52-
The behavior of *closed* enums has unexpected consquences when parsing a
52+
The behavior of *closed* enums has unexpected consequences when parsing a
5353
repeated field. When a `repeated Enum` field is parsed all unknown values will
5454
be placed in the
5555
[unknown field](/programming-guides/proto3/#unknowns)

content/programming-guides/field_presence.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ for generated APIs and using dynamic reflection):
157157
Field type | `optional` | Explicit Presence
158158
-------------------------------------------- | ---------- | -----------------
159159
Singular numeric (integer or floating point) | No |
160-
Singular enum | No |
161-
Singular string or bytes | No |
162160
Singular numeric (integer or floating point) | Yes | ✔️
161+
Singular enum | No |
163162
Singular enum | Yes | ✔️
163+
Singular string or bytes | No |
164164
Singular string or bytes | Yes | ✔️
165-
Singular message | Yes | ✔️
166165
Singular message | No | ✔️
166+
Singular message | Yes | ✔️
167167
Repeated | N/A |
168168
Oneofs | N/A | ✔️
169169
Maps | N/A |

content/programming-guides/proto2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,8 +1939,8 @@ Here are a few of the most commonly used options:
19391939
message types. This code is highly optimized.
19401940
* `CODE_SIZE`: The protocol buffer compiler will generate minimal classes
19411941
and will rely on shared, reflection-based code to implement
1942-
serialialization, parsing, and various other operations. The generated
1943-
code will thus be much smaller than with `SPEED`, but operations will be
1942+
serialization, parsing, and various other operations. The generated code
1943+
will thus be much smaller than with `SPEED`, but operations will be
19441944
slower. Classes will still implement exactly the same public API as they
19451945
do in `SPEED` mode. This mode is most useful in apps that contain a very
19461946
large number of `.proto` files and do not need all of them to be

content/programming-guides/proto3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ Here are a few of the most commonly used options:
14871487
message types. This code is highly optimized.
14881488
* `CODE_SIZE`: The protocol buffer compiler will generate minimal classes
14891489
and will rely on shared, reflection-based code to implement
1490-
serialialization, parsing, and various other operations. The generated
1491-
code will thus be much smaller than with `SPEED`, but operations will be
1490+
serialization, parsing, and various other operations. The generated code
1491+
will thus be much smaller than with `SPEED`, but operations will be
14921492
slower. Classes will still implement exactly the same public API as they
14931493
do in `SPEED` mode. This mode is most useful in apps that contain a very
14941494
large number of `.proto` files and do not need all of them to be

0 commit comments

Comments
 (0)