Skip to content

Commit 5bf0e31

Browse files
Protocol Buffer TeamLogofile
authored andcommitted
This documentation change includes the following:
* Adds anchor text to headings in `field_presence.md` so links can go to a specific section * Updates several topics to make them default to Editions examples * Fixes links in the Rust generated code topic PiperOrigin-RevId: 760628080 Change-Id: I2e2990e131a233ce456c9b236cbeb5aa933a8a46
1 parent 0dbc370 commit 5bf0e31

File tree

4 files changed

+46
-63
lines changed

4 files changed

+46
-63
lines changed

content/programming-guides/field_presence.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description = "Explains the various presence-tracking disciplines for protobuf f
66
type = "docs"
77
+++
88

9-
## Background
9+
## Background {#background}
1010

1111
*Field presence* is the notion of whether a protobuf field has a value. There
1212
are two different manifestations of presence for protobufs: *implicit presence*,
@@ -18,15 +18,15 @@ recommend always adding the `optional` label for proto3 basic types. This
1818
provides a smoother path to editions, which uses explicit presence by
1919
default.{{% /alert %}}
2020

21-
### Presence Disciplines
21+
### Presence Disciplines {#disciplines}
2222

2323
*Presence disciplines* define the semantics for translating between the *API
2424
representation* and the *serialized representation*. The *implicit presence*
2525
discipline relies upon the field value itself to make decisions at
2626
(de)serialization time, while the *explicit presence* discipline relies upon the
2727
explicit tracking state instead.
2828

29-
### Presence in *Tag-value stream* (Wire Format) Serialization
29+
### Presence in *Tag-value stream* (Wire Format) Serialization {#presence-tag-value}
3030

3131
The wire format is a stream of tagged, *self-delimiting* values. By definition,
3232
the wire format represents a sequence of *present* values. In other words, every
@@ -66,7 +66,7 @@ deserializing wire-formatted messages:
6666
APIs. However, out-of-range values may be stored as *unknown fields* in the
6767
API, even though the wire-format tag was recognized.
6868

69-
### Presence in *Named-field Mapping* Formats
69+
### Presence in *Named-field Mapping* Formats {#presence-named-field}
7070

7171
Protobufs can be represented in human-readable, textual forms. Two notable
7272
formats are TextFormat (the output format produced by generated message
@@ -104,7 +104,7 @@ practice, however, presence correctness can vary depending upon implementation
104104
choices, especially if JSON was chosen as a means to interoperate with clients
105105
not using protobufs.
106106

107-
### Presence in Proto2 APIs
107+
### Presence in Proto2 APIs {#presence-proto2}
108108

109109
This table outlines whether presence is tracked for fields in proto2 APIs (both
110110
for generated APIs and using dynamic reflection):
@@ -147,7 +147,7 @@ several methods:
147147
Repeated fields and maps do not track presence: there is no distinction between
148148
an *empty* and a *not-present* repeated field.
149149

150-
### Presence in Proto3 APIs
150+
### Presence in Proto3 APIs {#presence-proto3}
151151

152152
This table outlines whether presence is tracked for fields in proto3 APIs (both
153153
for generated APIs and using dynamic reflection):
@@ -187,7 +187,7 @@ required to have an enumerator value which maps to 0. By convention, this is an
187187
the domain of valid values for the application, this behavior can be thought of
188188
as tantamount to *explicit presence*.
189189

190-
### Presence in Editions APIs
190+
### Presence in Editions APIs {#presence-editions}
191191

192192
This table outlines whether presence is tracked for fields in editions APIs
193193
(both for generated APIs and using dynamic reflection):
@@ -239,7 +239,7 @@ For a singular field with numeric, enum, or string type:
239239
exception to this behavior is Dart, which generates `has_` methods with proto3
240240
proto schema files.{{% /alert %}}
241241

242-
### Considerations for Merging
242+
### Considerations for Merging {#merging}
243243

244244
Under the *implicit presence* rules, it is effectively impossible for a target
245245
field to merge-from its default value (using the protobuf's API merging
@@ -256,7 +256,7 @@ Updating to set a default value in this case requires some external mechanism,
256256
such as `FieldMask`. However, if presence *is* tracked, then all explicitly-set
257257
values -- even default values -- will be merged into the target.
258258

259-
### Considerations for change-compatibility
259+
### Considerations for change-compatibility {#change-compatibility}
260260

261261
Changing a field between *explicit presence* and *implicit presence* is a
262262
binary-compatible change for serialized values in wire format. However, the
@@ -334,7 +334,7 @@ this is not a safe change: client A requires (by `assert`) that the field is
334334
present; even without any modifications through the API, that requirement fails
335335
in a value- and peer-dependent case.
336336

337-
## How to Enable *Explicit Presence* in Proto3
337+
## How to Enable *Explicit Presence* in Proto3 {#enable-explicit-proto3}
338338

339339
These are the general steps to use field tracking support for proto3:
340340

@@ -344,7 +344,7 @@ These are the general steps to use field tracking support for proto3:
344344
1. Use the generated "hazzer" methods and "clear" methods in application code,
345345
instead of comparing or setting default values.
346346

347-
### `.proto` File Changes
347+
### `.proto` File Changes {#proto-file-changes}
348348

349349
This is an example of a proto3 message with fields which follow both *no
350350
presence* and *explicit presence* semantics:
@@ -362,7 +362,7 @@ message MyMessage {
362362
}
363363
```
364364

365-
### `protoc` Invocation
365+
### `protoc` Invocation {#protoc-invocation}
366366

367367
Presence tracking for proto3 messages is enabled by default
368368
[since v3.15.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.15.0)
@@ -399,7 +399,7 @@ message Msg {
399399
In the examples, a function `GetProto` constructs and returns a message of type
400400
`Msg` with unspecified contents.
401401

402-
#### C++ Example
402+
#### C++ Example {#cpp-example}
403403

404404
Implicit presence:
405405

@@ -427,7 +427,7 @@ if (m.has_foo()) {
427427
}
428428
```
429429

430-
#### C# Example
430+
#### C# Example {#csharp-example}
431431

432432
Implicit presence:
433433

@@ -455,7 +455,7 @@ if (m.HasFoo) {
455455
}
456456
```
457457

458-
#### Go Example
458+
#### Go Example {#go-example}
459459

460460
Implicit presence:
461461

@@ -483,7 +483,7 @@ if m.Foo != nil {
483483
}
484484
```
485485

486-
#### Java Example
486+
#### Java Example {#java-example}
487487

488488
These examples use a `Builder` to demonstrate clearing. Simply checking presence
489489
and getting values from a `Builder` follows the same API as the message type.
@@ -514,7 +514,7 @@ if (m.hasFoo()) {
514514
}
515515
```
516516

517-
#### Python Example
517+
#### Python Example {#python-example}
518518

519519
Implicit presence:
520520

@@ -540,7 +540,7 @@ else:
540540
m.foo = 1
541541
```
542542

543-
#### Ruby Example
543+
#### Ruby Example {#ruby-example}
544544

545545
Implicit presence:
546546

@@ -568,7 +568,7 @@ else
568568
end
569569
```
570570

571-
#### Javascript Example
571+
#### Javascript Example {#js-example}
572572

573573
Implicit presence:
574574

@@ -596,7 +596,7 @@ if (m.hasFoo()) {
596596
}
597597
```
598598

599-
#### Objective-C Example
599+
#### Objective-C Example {#objc-example}
600600

601601
Implicit presence:
602602

content/reference/cpp/arenas.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buffer compiler generates in addition to the code described in the
1111
[C++ Generated Code Guide](/reference/cpp/cpp-generated)
1212
when arena allocation is enabled. It assumes that you are familiar with the
1313
material in the
14-
[language guide](/programming-guides/proto2) and the
14+
[language guide](/programming-guides/editions) and the
1515
[C++ Generated Code Guide](/reference/cpp/cpp-generated).
1616

1717
## Why Use Arena Allocation? {#why}
@@ -81,7 +81,7 @@ can see a more extensive [example](#example) at the end of the document.
8181
## Arena Class API {#arenaclass}
8282

8383
You create message objects on the arena using the
84-
[`google::protobuf::Arena`](/reference/cpp/api-docs/google.protobuf.arena.md)
84+
[`google::protobuf::Arena`](/reference/cpp/api-docs/google.protobuf.arena)
8585
class. This class implements the following public methods.
8686

8787
### Constructors {#constructors}
@@ -253,11 +253,10 @@ message objects are allocated depends on where they are defined:
253253
arena. This means that when the arena is destroyed, the object will be freed
254254
along with the objects on the arena itself.
255255

256-
For either of these field definitions:
256+
For the field definition:
257257

258258
```proto
259-
optional Bar foo = 1;
260-
required Bar foo = 1;
259+
Bar foo = 1;
261260
```
262261

263262
The following methods are added or have some special behavior when arena
@@ -538,30 +537,29 @@ allocation API.
538537

539538
```proto
540539
// my_feature.proto
540+
edition = "2023";
541541
542-
syntax = "proto2";
543542
import "nested_message.proto";
544543
545544
package feature_package;
546545
547546
// NEXT Tag to use: 4
548547
message MyFeatureMessage {
549-
optional string feature_name = 1;
548+
string feature_name = 1;
550549
repeated int32 feature_data = 2;
551-
optional NestedMessage nested_message = 3;
550+
NestedMessage nested_message = 3;
552551
};
553552
```
554553

555554
```proto
556555
// nested_message.proto
557-
558-
syntax = "proto2";
556+
edition = "2023";
559557
560558
package feature_package;
561559
562560
// NEXT Tag to use: 2
563561
message NestedMessage {
564-
optional int32 feature_id = 1;
562+
int32 feature_id = 1;
565563
};
566564
```
567565

@@ -575,7 +573,7 @@ Arena arena;
575573
MyFeatureMessage* arena_message =
576574
google::protobuf::Arena::Create<MyFeatureMessage>(&arena);
577575

578-
arena_message->set_feature_name("Proto2 Arena");
576+
arena_message->set_feature_name("Editions Arena");
579577
arena_message->mutable_feature_data()->Add(2);
580578
arena_message->mutable_feature_data()->Add(4);
581579
arena_message->mutable_nested_message()->set_feature_id(247);

content/reference/csharp/csharp-generated.md

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,12 @@ description = "Describes exactly what C# code the protocol buffer compiler gener
66
type = "docs"
77
+++
88

9-
You should
10-
read the
11-
[proto3 language guide](/programming-guides/proto3)
9+
You should read the
10+
[proto2 language guide](/programming-guides/proto2),
11+
[proto3 language guide](/programming-guides/proto3), or
12+
[editions language guide](/programming-guides/editions)
1213
before reading this document.
1314

14-
{{% alert title="Note" color="note" %}}
15-
The protobuf compiler can generate C\# interfaces for definitions using `proto2`
16-
syntax starting from release 3.10. Refer to the
17-
[proto2 language guide](/programming-guides/proto2) for
18-
details of the semantics of `proto2` definitions, and see
19-
`docs/csharp/proto2.md`
20-
([view on GitHub](https://github.com/protocolbuffers/protobuf/blob/master/docs/csharp/proto2.md))
21-
for details on the generated C\# code for proto2.
22-
{{% /alert %}}
23-
2415
## Compiler Invocation {#invocation}
2516

2617
The protocol buffer compiler produces C\# output when invoked with the
@@ -31,13 +22,6 @@ subdirectories of the specified directory. The compiler creates a single source
3122
file for each `.proto` file input, defaulting to an extension of `.cs` but
3223
configurable via compiler options.
3324

34-
Only `proto3` messages are supported by the C\# code generator. Ensure that each
35-
`.proto` file begins with a declaration of:
36-
37-
```proto
38-
syntax = "proto3";
39-
```
40-
4125
### C\#-specific Options {#compiler_options}
4226

4327
You can provide further C\# options to the protocol buffer compiler using the
@@ -123,7 +107,8 @@ is provided as part of Protocol Buffers. A cut down version of `timestamp.proto`
123107
looks like this:
124108
125109
```proto
126-
syntax = "proto3";
110+
edition = "2023";
111+
127112
package google.protobuf;
128113
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
129114
@@ -331,14 +316,14 @@ method.
331316

332317
### Wrapper Type Fields {#wrapper_types}
333318

334-
Most of the well-known types in proto3 do not affect code generation, but the
335-
wrapper types (`StringWrapper`, `Int32Wrapper` etc) change the type and
336-
behaviour of the properties.
319+
Most of the well-known types do not affect code generation, but the wrapper
320+
types (such as `StringWrapper` and `Int32Wrapper`) change the type and behavior
321+
of the properties.
337322

338-
All of the wrapper types that correspond to C\# value types (`Int32Wrapper`,
339-
`DoubleWrapper`, `BoolWrapper` etc) are mapped to `Nullable<T>` where `T` is the
340-
corresponding non-nullable type. For example, a field of type `DoubleValue`
341-
results in a C\# property of type `Nullable<double>`.
323+
All of the wrapper types that correspond to C\# value types (such as
324+
`Int32Wrapper`, `DoubleWrapper`, and `BoolWrapper`) are mapped to `Nullable<T>`
325+
where `T` is the corresponding non-nullable type. For example, a field of type
326+
`DoubleValue` results in a C\# property of type `Nullable<double>`.
342327

343328
Fields of type `StringWrapper` or `BytesWrapper` result in C\# properties of
344329
type `string` and `ByteString` being generated, but with a default value of

content/reference/rust/rust-generated.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ generates for any given protocol definition.
1212

1313
Any differences between proto2 and proto3 generated code are highlighted. You
1414
should read the
15-
[proto2 language guide](/programming-guides/proto2.md)
15+
[proto2 language guide](/programming-guides/proto2)
1616
and/or
17-
[proto3 language guide](/programming-guides/proto3.md)
17+
[proto3 language guide](/programming-guides/proto3)
1818
before reading this document.
1919

2020
## Protobuf Rust {#rust}
@@ -26,7 +26,7 @@ sit on top of other existing protocol buffer implementations that we refer to as
2626
The decision to support multiple non-Rust kernels has significantly influenced
2727
our public API, including the choice to use custom types like `ProtoStr` over
2828
Rust std types like `str`. See
29-
[Rust Proto Design Decisions](/reference/rust/rust-design-decisions.md)
29+
[Rust Proto Design Decisions](/reference/rust/rust-design-decisions)
3030
for more on this topic.
3131

3232
## Generated Filenames {#filenames}

0 commit comments

Comments
 (0)