Skip to content

Commit 802132f

Browse files
authored
Merge branch 'main' into patch-1
2 parents f6c72ad + 2a776bb commit 802132f

31 files changed

+1946
-194
lines changed

config.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
baseURL = 'https://protobuf.dev'
22
languageCode = 'en-us'
33
title = 'Protocol Buffers Documentation'
4-
sidebar_search_disable = true
54

65
# Theme
76
[module]
@@ -80,7 +79,7 @@ weight = 1
8079
# See a complete list of available styles at https://xyproto.github.io/splash/docs/all.html
8180
style = "tango"
8281
# Uncomment if you want your chosen highlight style used for code blocks without a specified language
83-
# guessSyntax = "true"
82+
guessSyntax = "true"
8483

8584
# Everything below this are Site Params
8685

@@ -148,7 +147,7 @@ navbar_translucent_over_cover_disable = false
148147
# Enable to show the side bar menu in its compact state.
149148
sidebar_menu_compact = false
150149
# Set to true to hide the sidebar search box (the top nav search box will still be displayed if search is enabled)
151-
sidebar_search_disable = false
150+
sidebar_search_disable = true
152151

153152
# ui.sidebar_menu_compact = true
154153
ui.ul_show = 2

content/_index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ message Person {
3636
</div>
3737
<div class="col-md">
3838

39-
```proto
39+
```java
40+
// Java code
4041
Person john = Person.newBuilder()
4142
.setId(1234)
4243
.setName("John Doe")
@@ -51,7 +52,8 @@ john.writeTo(output);
5152
</div>
5253
<div class="col-md">
5354

54-
```proto
55+
```cpp
56+
// C++ code
5557
Person john;
5658
fstream input(argv[1],
5759
ios::in | ios::binary);

content/getting-started/cpptutorial.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ if you want one of your fields to have one of a predefined list of values --
127127
here you want to specify that a phone number can be one of the following phone
128128
types: `MOBILE`, `HOME`, or `WORK`.
129129

130-
The " = 1", " = 2" markers on each element identify the unique "tag" that field
131-
uses in the binary encoding. Tag numbers 1-15 require one less byte to encode
132-
than higher numbers, so as an optimization you can decide to use those tags for
133-
the commonly used or repeated elements, leaving tags 16 and higher for
134-
less-commonly used optional elements. Each element in a repeated field requires
135-
re-encoding the tag number, so repeated fields are particularly good candidates
136-
for this optimization.
130+
The " = 1", " = 2" markers on each element identify the unique field number that
131+
field uses in the binary encoding. Field numbers 1-15 require one less byte to
132+
encode than higher numbers, so as an optimization you can decide to use those
133+
numbers for the commonly used or repeated elements, leaving field numbers 16 and
134+
higher for less-commonly used optional elements. Each element in a repeated
135+
field requires re-encoding the field number, so repeated fields are particularly
136+
good candidates for this optimization.
137137

138138
Each field must be annotated with one of the following modifiers:
139139

@@ -550,12 +550,12 @@ your new buffers to be backwards-compatible, and your old buffers to be
550550
forward-compatible -- and you almost certainly do want this -- then there are
551551
some rules you need to follow. In the new version of the protocol buffer:
552552
553-
- you *must not* change the tag numbers of any existing fields.
553+
- you *must not* change the field numbers of any existing fields.
554554
- you *must not* add or delete any required fields.
555555
- you *may* delete optional or repeated fields.
556-
- you *may* add new optional or repeated fields but you must use fresh tag
557-
numbers (that is, tag numbers that were never used in this protocol buffer,
558-
not even by deleted fields).
556+
- you *may* add new optional or repeated fields but you must use fresh field
557+
numbers (that is, field numbers that were never used in this protocol
558+
buffer, not even by deleted fields).
559559
560560
(There are
561561
[some exceptions](/programming-guides/proto#updating) to
@@ -567,7 +567,7 @@ simply have their default value, and deleted repeated fields will be empty. New
567567
code will also transparently read old messages. However, keep in mind that new
568568
optional fields will not be present in old messages, so you will need to either
569569
check explicitly whether they're set with `has_`, or provide a reasonable
570-
default value in your `.proto` file with `[default = value]` after the tag
570+
default value in your `.proto` file with `[default = value]` after the field
571571
number. If the default value is not specified for an optional element, a
572572
type-specific default value is used instead: for strings, the default value is
573573
the empty string. For booleans, the default value is false. For numeric types,

content/getting-started/pythontutorial.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -326,62 +326,60 @@ the file again. The parts which directly call or reference code generated by the
326326
protocol compiler are highlighted.
327327
328328
```python
329-
#! /usr/bin/python
329+
#!/usr/bin/env python3
330330
331331
import addressbook_pb2
332332
import sys
333333
334334
# This function fills in a Person message based on user input.
335335
def PromptForAddress(person):
336-
person.id = int(raw_input("Enter person ID number: "))
337-
person.name = raw_input("Enter name: ")
336+
person.id = int(input("Enter person ID number: "))
337+
person.name = input("Enter name: ")
338338
339-
email = raw_input("Enter email address (blank for none): ")
339+
email = input("Enter email address (blank for none): ")
340340
if email != "":
341341
person.email = email
342342
343343
while True:
344-
number = raw_input("Enter a phone number (or leave blank to finish): ")
344+
number = input("Enter a phone number (or leave blank to finish): ")
345345
if number == "":
346346
break
347347
348348
phone_number = person.phones.add()
349349
phone_number.number = number
350350
351-
type = raw_input("Is this a mobile, home, or work phone? ")
352-
if type == "mobile":
351+
phone_type = input("Is this a mobile, home, or work phone? ")
352+
if phone_type == "mobile":
353353
phone_number.type = addressbook_pb2.Person.PhoneType.MOBILE
354-
elif type == "home":
354+
elif phone_type == "home":
355355
phone_number.type = addressbook_pb2.Person.PhoneType.HOME
356-
elif type == "work":
356+
elif phone_type == "work":
357357
phone_number.type = addressbook_pb2.Person.PhoneType.WORK
358358
else:
359-
print "Unknown phone type; leaving as default value."
359+
print("Unknown phone type; leaving as default value.")
360360
361361
# Main procedure: Reads the entire address book from a file,
362362
# adds one person based on user input, then writes it back out to the same
363363
# file.
364364
if len(sys.argv) != 2:
365-
print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
365+
print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE")
366366
sys.exit(-1)
367367
368368
address_book = addressbook_pb2.AddressBook()
369369
370370
# Read the existing address book.
371371
try:
372-
f = open(sys.argv[1], "rb")
373-
address_book.ParseFromString(f.read())
374-
f.close()
372+
with open(sys.argv[1], "rb") as f:
373+
address_book.ParseFromString(f.read())
375374
except IOError:
376-
print sys.argv[1] + ": Could not open file. Creating a new one."
375+
print(sys.argv[1] + ": Could not open file. Creating a new one.")
377376
378377
# Add an address.
379378
PromptForAddress(address_book.people.add())
380379
381380
# Write the new address book back to disk.
382-
f = open(sys.argv[1], "wb")
383-
f.write(address_book.SerializeToString())
384-
f.close()
381+
with open(sys.argv[1], "wb") as f:
382+
f.write(address_book.SerializeToString())
385383
```
386384
387385
## Reading a Message {#reading-a-message}
@@ -391,40 +389,39 @@ information out of it! This example reads the file created by the above example
391389
and prints all the information in it.
392390
393391
```python
394-
#! /usr/bin/python
392+
#!/usr/bin/env python3
395393
396394
import addressbook_pb2
397395
import sys
398396
399397
# Iterates though all people in the AddressBook and prints info about them.
400398
def ListPeople(address_book):
401399
for person in address_book.people:
402-
print "Person ID:", person.id
403-
print " Name:", person.name
400+
print("Person ID:", person.id)
401+
print(" Name:", person.name)
404402
if person.HasField('email'):
405-
print " E-mail address:", person.email
403+
print(" E-mail address:", person.email)
406404
407405
for phone_number in person.phones:
408406
if phone_number.type == addressbook_pb2.Person.PhoneType.MOBILE:
409-
print " Mobile phone #: ",
407+
print(" Mobile phone #: ", end="")
410408
elif phone_number.type == addressbook_pb2.Person.PhoneType.HOME:
411-
print " Home phone #: ",
409+
print(" Home phone #: ", end="")
412410
elif phone_number.type == addressbook_pb2.Person.PhoneType.WORK:
413-
print " Work phone #: ",
414-
print phone_number.number
411+
print(" Work phone #: ", end="")
412+
print(phone_number.number)
415413
416414
# Main procedure: Reads the entire address book from a file and prints all
417415
# the information inside.
418416
if len(sys.argv) != 2:
419-
print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
417+
print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE")
420418
sys.exit(-1)
421419
422420
address_book = addressbook_pb2.AddressBook()
423421
424422
# Read the existing address book.
425-
f = open(sys.argv[1], "rb")
426-
address_book.ParseFromString(f.read())
427-
f.close()
423+
with open(sys.argv[1], "rb") as f:
424+
address_book.ParseFromString(f.read())
428425
429426
ListPeople(address_book)
430427
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
table tbody, th, td {
2+
border: 1px solid #818589 !important;
3+
padding-top: 2px;
4+
padding-bottom: 2px;
5+
padding-left: 5px;
6+
padding-right: 5px;
7+
text-align: center;
8+
9+
}
10+
11+
tbody td {
12+
background: #fff;
13+
}
14+
15+
tbody td.red {
16+
background: #f00;
17+
color: #fff;
18+
}
19+
20+
tbody td.blue {
21+
background: #c9daf8;
22+
}
23+
24+
tbody td.green {
25+
background: #d9ead3;
26+
}
27+
28+
tbody td.gray {
29+
background: #f3f3f3;
30+
}
31+
32+
tbody td.yellow {
33+
background: #fff2cc;
34+
}

content/news/2022-08-03.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,3 @@ automatically generated by GitHub on the release page.
8888

8989
In 22.0 we plan to rename Maven artifacts to use “RC” instead of “rc-” as the
9090
release candidate prefix.
91-
92-
### Releasing Only Ruby Source Gems {#gems}
93-
94-
We currently release multiple Ruby gems that are compiled for different
95-
architectures. Starting in 22.0, we plan to release only a single ruby source
96-
gem that contains source code and will be compiled on the host system.

content/programming-guides/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ system."
668668
If the enhancement field in `PhotoEnhancementReply` were a scalar or enum, this
669669
would be much harder to support.
670670

671+
This applies equally to maps. It is much easier to add additional fields to a
672+
map value if it's already a message rather than having to migrate from
673+
`map<string, string>` to `map<string, MyProto>`.
674+
671675
One exception:
672676

673677
Latency-critical applications will find parallel arrays of primitive types are

content/programming-guides/dos-donts.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,15 @@ For example:
166166

167167
* `java_outer_classname` should follow
168168
https://google.github.io/styleguide/javaguide.html#s5.2.2-class-names
169+
169170
* `java_package` and `java_alt_package` should follow
170171
https://google.github.io/styleguide/javaguide.html#s5.2.1-package-names
171172

173+
* `package`, although used for Java when `java_package` is not present, always
174+
directly corresponds to C++ namespace and thus should follow
175+
https://google.github.io/styleguide/cppguide.html#Namespace_Names.
176+
If these style guides conflict, use `java_package` for Java.
177+
172178
## **Never** Use Text-format Messages for Interchange
173179

174180
Deserializing of text-format protocol buffers will fail when the binary is

content/programming-guides/encoding.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,13 @@ This is the *two's complement* of 2, defined in unsigned arithmetic as `~0 - 2 +
183183
1`, where `~0` is the all-ones 64-bit integer. It is a useful exercise to
184184
understand why this produces so many ones.
185185

186-
On the other hand, `sintN` uses the "ZigZag" encoding instead of two's
187-
complement to encode negative integers. Positive integers `n` are encoded as `2
188-
* n` (the even numbers), while negative integers `-n` are encoded as `2 * n + 1`
189-
(the odd numbers). The encoding thus "zig-zags" between positive and negative
190-
numbers. For example:
186+
<!-- mdformat off(the asterisks cause bullets) -->
187+
`sintN` uses the "ZigZag" encoding instead of two's complement to encode
188+
negative integers. Positive integers `n` are encoded as `2 * n` (the even
189+
numbers), while negative integers `-n` are encoded as `2 * n + 1` (the odd
190+
numbers). The encoding thus "zig-zags" between positive and negative numbers.
191+
For example:
192+
<!-- mdformat on -->
191193

192194
Signed Original | Encoded As
193195
--------------- | ----------
@@ -202,7 +204,7 @@ Signed Original | Encoded As
202204
Using some bit tricks, it's cheap to convert `n` into its ZigZag representation:
203205

204206
```
205-
n + n + (n < 0)
207+
((n + n) ^ -(n < 0)) - (n < 0)
206208
```
207209

208210
Here, we assume that the boolean `n < 0` is converted into an integer 1 if true
@@ -294,7 +296,7 @@ Missing `optional` fields are easy to encode: we just leave out the record if
294296
it's not present. This means that "huge" protos with only a few fields set are
295297
quite sparse.
296298

297-
`repeated` fields are a bit more compicated. Ordinary (not [packed](#packed))
299+
`repeated` fields are a bit more complicated. Ordinary (not [packed](#packed))
298300
repeated fields emit one record for every element of the field. Thus, if we have
299301

300302
```proto

0 commit comments

Comments
 (0)