Skip to content

Commit afec088

Browse files
Protocol Buffer TeamLogofile
Protocol Buffer Team
authored andcommitted
This documentation change includes the following:
* Wording tweaks in `api.md` * Adds a new section, "Do put new enum aliases last," to the `dos-donts.md` topic * Creates a new section, https://protobuf.dev/design-decisions, to contain related topics * Adds a new topic about installing Protoc. This topic is derived from https://grpc.io/docs/protoc-installation/ * Updates `deserialize-debug.md` for changes being made in v30 * Updates to `field_presence.md` * Wording tweak in `proto2.md` * Updates to methods in `cpp-generated.md` * Adds the new topic, `string-view.md` * Corrects oneof samples in `rust-generated.md` * Updates the Docsy template to v0.11.0 PiperOrigin-RevId: 724428621 Change-Id: I48a1b22e6feb855d4b5154eb6680b8c0687fba4a
1 parent fe32cc1 commit afec088

File tree

13 files changed

+421
-67
lines changed

13 files changed

+421
-67
lines changed

content/best-practices/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ More generally, choose the right primitive type. See the Scalar Value Types
294294
table in the
295295
[Protocol Buffer Language Guide](/programming-guides/proto2#scalar).
296296

297-
### Returning HTML in a Front-End Proto {#returning-html}
297+
### Don't Return HTML in a Front-End Proto {#returning-html}
298298

299299
With a JavaScript client, it's tempting to return HTML or
300300
JSON in a field of your API. This is a slippery
@@ -408,7 +408,7 @@ message InternalPaginationToken {
408408
}
409409
```
410410

411-
## Group Related Fields into a New Message. Nest Only Fields with High Cohesion {#group-related-fields}
411+
## Group Related Fields into a new `message`. Nest Only Fields with High Cohesion {#group-related-fields}
412412

413413
```proto
414414
message Foo {

content/best-practices/dos-donts.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ no one accidentally re-uses it in the future. Just `reserved 2, 3;` is enough.
3838
You can also reserve names to avoid recycling now-deleted value names: `reserved
3939
"FOO", "BAR";`.
4040

41+
<a id="do-put-new-enum-aliases-last"></a>
42+
43+
## **Do** Put New Enum Aliases Last {#enum-aliases-last}
44+
45+
When you add a new enum alias, put the new name last to give
46+
services time to pick it up.
47+
48+
To safely remove the original name (if it's being used for interchange, which it
49+
[shouldn't](#text-format-interchange)), you must do the following:
50+
51+
* Add the new name below the old name and deprecate the old one (serializers
52+
will continue to use the old name)
53+
54+
* After every parser has the schema rolled out, swap the order of the two
55+
names (serializers will begin using the new name, parsers accept both)
56+
57+
* After every serializer has that version of the schema, you can delete the
58+
deprecated name.
59+
60+
> **Note:** While in theory clients shouldn't be using the old name for
61+
> interchange, it's still polite to follow the above steps, especially for
62+
> widely-used enum names.
63+
4164
<a id="dont-change-the-type-of-a-field"></a>
4265

4366
## **Don't** Change the Type of a Field {#change-type}

content/design-decisions/_index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
+++
2+
title = "Protobuf Team Design Decisions"
3+
weight = 88
4+
description = "Covers the design decisions the Protobuf team has made"
5+
type = "docs"
6+
no_list = "true"
7+
linkTitle = "Design Decisions"
8+
+++
9+
10+
This section contains some positions of the Protobuf team that inform our design
11+
and implementation decisions.
12+
13+
These positions were taken after careful consideration and won't be overturned
14+
on a whim, but are open to being revisited as we gain new information, and as
15+
things develop in the broader ecosystem context.
16+
17+
* [No Nullable Setters/Getters](/design-decisions/nullable-getters-setters)

content/programming-guides/nullable-getters-setters.md renamed to content/design-decisions/nullable-getters-setters.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title = "No Nullable Setters/Getters Support"
33
weight = 89
44
description = "Covers why Protobuf doesn't support nullable setters and getters"
55
type = "docs"
6+
aliases = "/programming-guides/nullable-getters-setters/"
67
+++
78

89
We have heard feedback that some folks would like protobuf to support nullable
@@ -15,6 +16,11 @@ The biggest reason not to have nullable fields is the intended behavior of
1516
default values specified in a `.proto` file. By design, calling a getter on an
1617
unset field will return the default value of that field.
1718

19+
**Note:** C# does treat *message* fields as nullable. This inconsistency with
20+
other languages stems from the lack of immutable messages, which makes it
21+
impossible to create shared immutable default instances. Because message fields
22+
can't have defaults, there's no functional problem with this.
23+
1824
As an example, consider this `.proto` file:
1925

2026
```proto

content/installation.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
+++
2+
title = "Protocol Buffer Compiler Installation"
3+
weight = 15
4+
description = "How to install the protocol buffer compiler."
5+
type = "docs"
6+
no_list = "true"
7+
linkTitle = "Protoc Installation"
8+
+++
9+
10+
The protocol buffer compiler, `protoc`, is used to compile `.proto` files, which
11+
contain service and message definitions. Choose one of the methods given below
12+
to install `protoc`.
13+
14+
### Install Pre-compiled Binaries (Any OS) {#binary-install}
15+
16+
To install the latest release of the protocol compiler from pre-compiled
17+
binaries, follow these instructions:
18+
19+
1. From https://github.com/google/protobuf/releases, manually download the zip
20+
file corresponding to your operating system and computer architecture
21+
(`protoc-<version>-<os>-<arch>.zip`), or fetch the file using commands such
22+
as the following:
23+
24+
```sh
25+
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
26+
curl -LO $PB_REL/download/v< param protoc-version >/protoc-< param protoc-version >-linux-x86_64.zip
27+
```
28+
29+
2. Unzip the file under `$HOME/.local` or a directory of your choice. For
30+
example:
31+
32+
```sh
33+
unzip protoc-< param protoc-version >-linux-x86_64.zip -d $HOME/.local
34+
```
35+
36+
3. Update your environment's path variable to include the path to the `protoc`
37+
executable. For example:
38+
39+
```sh
40+
export PATH="$PATH:$HOME/.local/bin"
41+
```
42+
43+
### Install Using a Package Manager {#package-manager}
44+
45+
{{% alert title="Warning" color="warning" %}} Run
46+
`protoc --version` to check the version of `protoc` after using a package
47+
manager for installation to ensure that it is sufficiently recent. The versions
48+
of `protoc` installed by some package managers can be quite dated. See the
49+
[Version Support page](https://protobuf.dev/support/version-support) to compare
50+
the output of the version check to the minor version number of the supported
51+
version of the language(s) you are
52+
using.{{% /alert %}}
53+
54+
You can install the protocol compiler, `protoc`, with a package manager under
55+
Linux, macOS, or Windows using the following commands.
56+
57+
- Linux, using `apt` or `apt-get`, for example:
58+
59+
```sh
60+
apt install -y protobuf-compiler
61+
protoc --version # Ensure compiler version is 3+
62+
```
63+
64+
- MacOS, using [Homebrew](https://brew.sh):
65+
66+
```sh
67+
brew install protobuf
68+
protoc --version # Ensure compiler version is 3+
69+
```
70+
71+
- Windows, using
72+
[Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/)
73+
74+
```sh
75+
> winget install protobuf
76+
> protoc --version # Ensure compiler version is 3+
77+
```
78+
79+
### Other Installation Options {#other}
80+
81+
If you'd like to build the protocol compiler from sources, or access older
82+
versions of the pre-compiled binaries, see
83+
[Download Protocol Buffers](https://protobuf.dev/downloads).

content/news/v30.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ be parseable by Protobuf TextFormat Parsers.
5555
Read more about this in the
5656
[news article released November 21, 2024](/news/2024-11-21).
5757

58-
### Removing a a Reflection-related Function {#removing-mutable-repeated}
58+
### Removing a Reflection-related Function {#removing-mutable-repeated}
5959

6060
We are removing the following reflection-related function:
6161
`MutableRepeatedFieldRef<T>::Reserve()`.

content/programming-guides/deserialize-debug.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ description = "How to log debugging information in Protocol Buffers."
55
type = "docs"
66
+++
77

8-
From version 29.x, `DebugString` APIs (`proto2::DebugString`,
9-
`proto2::ShortDebugString`, `proto2::Utf8DebugString`) are deprecated.
10-
DebugString users should migrate to some Abseil string functions (such as
11-
`absl::StrCat`, `absl::StrFormat`, `absl::StrAppend`, AND `absl::Substitute`),
12-
Abseil logging API, and some Protobuf APIs (`proto2::ShortFormat`,
13-
`proto2::Utf8Format`) to automatically convert proto arguments into a new
14-
debugging format .
8+
From version 30.x, Protobuf `DebugString` APIs (`Message::DebugString`,
9+
`Message::ShortDebugString`, `Message::Utf8DebugString`), additional Protobuf
10+
APIs (`proto2::ShortFormat`, `proto2::Utf8Format`), Abseil string functions
11+
(such as `absl::StrCat`, `absl::StrFormat`, `absl::StrAppend`, and
12+
`absl::Substitute`), and Abseil logging API will begin to automatically convert
13+
proto arguments into a new debugging format
14+
. See the related announcement
15+
[here](/news/2024-12-04/).
1516

1617
Unlike the Protobuf DebugString output format, the new debugging format
1718
automatically redacts sensitive fields by replacing their values with the string
@@ -36,8 +37,7 @@ DebugString format in two ways:
3637
"[REDACTED]" (without the quotes)
3738

3839
The new debugging format never removes any field names; it only replaces the
39-
value with
40-
"[REDACTED]" if the field is considered sensitive.
40+
value with "[REDACTED]" if the field is considered sensitive.
4141
**If you don't see certain fields in the output, it is because those fields are
4242
not set in the proto.**
4343

@@ -83,8 +83,8 @@ systems can change and code gets re-used.
8383
This is intentional. Don't attempt to parse the output of this debug format. We
8484
reserve the right to change the syntax without notice. The debug format syntax
8585
randomly changes per process to prevent inadvertent dependencies. If a syntactic
86-
change in the debug format would break your system, chances are you shouldn't
87-
use the debug representation of a proto.
86+
change in the debug format would break your system, chances are you should be
87+
using a TextFormat API rather than using the debug representation of a proto.
8888

8989
## FAQ
9090

content/programming-guides/field_presence.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ deserializing wire-formatted messages:
5252
- For enums, the default is the zero-valued enumerator.
5353
- For strings, bytes, and repeated fields, the default is the zero-length
5454
value.
55-
- For messages, the default is the language-specific null value.
5655
- "Empty" length-delimited values (such as empty strings) can be validly
5756
represented in serialized values: the field is "present," in the sense that
5857
it appears in the wire format. However, if the generated API does not track
@@ -588,7 +587,7 @@ if (m.hasFoo()) {
588587
Implicit presence:
589588

590589
```objective-c
591-
Msg *m = [[Msg alloc] init];
590+
Msg *m = [Msg message];
592591
if (m.foo != 0) {
593592
// "Clear" the field:
594593
m.foo = 0;
@@ -601,13 +600,13 @@ if (m.foo != 0) {
601600
Explicit presence:
602601

603602
```objective-c
604-
Msg *m = [[Msg alloc] init];
605-
if (m.hasFoo()) {
603+
Msg *m = [Msg message];
604+
if ([m hasFoo]) {
606605
// Clear the field:
607606
[m clearFoo];
608607
} else {
609608
// Field is not present, so set it.
610-
[m setFoo:1];
609+
m.foo = 1;
611610
}
612611
```
613612

@@ -639,9 +638,9 @@ Repeated field & map | no
639638

640639
Is field presence tracked?
641640

642-
Field type | Tracked?
643-
-------------------------------------------------- | --------
644-
Default | yes
645-
`features.field_presence` set to `LEGACY_REQUIRED` | yes
646-
`features.field_presence` set to `IMPLICIT` | no
647-
Repeated field & map | no
641+
Field type (in descending prescendence) | Tracked?
642+
-------------------------------------------------------------------- | --------
643+
Repeated field & map | no
644+
Message and Oneof fields | yes
645+
Other singular fields if `features.field_presence` set to `IMPLICIT` | no
646+
All other fields | yes

content/programming-guides/proto2.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,12 +2008,12 @@ Here are a few of the most commonly used options:
20082008
numeric type, it causes a more compact
20092009
[encoding](/programming-guides/encoding#packed) to be
20102010
used. The only reason to not use this option is if you need compatibility
2011-
with parsers prior to version 2.3.0. When these older parsers would ignore
2012-
packed data when it was not expected. Therefore, it was not possible to
2013-
change an existing field to packed format without breaking wire
2014-
compatibility. In 2.3.0 and later, this change is safe, as parsers for
2015-
packable fields will always accept both formats, but be careful if you have
2016-
to deal with old programs using old protobuf versions.
2011+
with parsers prior to version 2.3.0. These older parsers would ignore packed
2012+
data when it was not expected. Therefore, it was not possible to change an
2013+
existing field to packed format without breaking wire compatibility. In
2014+
2.3.0 and later, this change is safe, as parsers for packable fields will
2015+
always accept both formats, but be careful if you have to deal with old
2016+
programs using old protobuf versions.
20172017
20182018
```proto
20192019
repeated int32 samples = 4 [packed = true];

0 commit comments

Comments
 (0)