Skip to content

Commit 84095cb

Browse files
authored
Merge branch 'main' into patch-1
2 parents d934941 + cb12851 commit 84095cb

File tree

20 files changed

+210
-116
lines changed

20 files changed

+210
-116
lines changed

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/includes/version-tables.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
table tbody, th, td {
2-
border: 1px solid #818589;
2+
border: 1px solid #818589 !important;
33
padding-top: 2px;
44
padding-bottom: 2px;
55
padding-left: 5px;

content/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ When defining `.proto` files, you can specify that a field is either `optional`
245245
or `repeated` (proto2 and proto3) or `singular` (proto3). (The option to set a
246246
field to `required` is absent in proto3 and strongly discouraged in proto2. For
247247
more on this, see "Required is Forever" in
248-
[Specifying Field Rules](/programming-guides/proto3#specifying-field-rules).)
248+
[Specifying Field Rules](/programming-guides/proto3/#specifying-field-rules).)
249249
250250
After setting the optionality/repeatability of a field, you specify the data
251251
type. Protocol buffers support the usual primitive data types, such as integers,
252252
booleans, and floats. For the full list, see
253-
[Scalar Value Types](/programming-guides/proto3#scalar).
253+
[Scalar Value Types](/programming-guides/proto3/#scalar).
254254
255255
A field can also be of:
256256

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/encoding.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Signed Original | Encoded As
204204
Using some bit tricks, it's cheap to convert `n` into its ZigZag representation:
205205

206206
```
207-
n + n + (n < 0)
207+
((n + n) ^ -(n < 0)) - (n < 0)
208208
```
209209

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

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

302302
```proto
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ linkTitle: "Language Guide (proto 2)"
66
no_list: "true"
77
type: docs
88
description: "This topic covers how to use the version 2 of Protocol Buffers in your project. It contains language-agnostic content. For information specific to the language you're using, see the corresponding documentation for your language."
9+
aliases:
10+
- /programming-guides/proto/
911
---
1012

1113
This guide describes how to use the protocol buffer language to structure your

content/reference/cpp/api-docs/google.protobuf.map.md

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

content/reference/cpp/cpp-generated.md

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ generated code are highlighted - note that these differences are in the
1515
generated code as described in this document, not the base message
1616
classes/interfaces, which are the same in both versions. You should read the
1717
[proto2 language guide](/programming-guides/proto) and/or
18-
[proto3 language guide](/programming-guides/proto3) before reading this
19-
document.
18+
[proto3 language guide](/programming-guides/proto3)
19+
before reading this document.
2020

2121
## Compiler Invocation {#invocation}
2222

@@ -267,17 +267,19 @@ The compiler will generate the following accessor methods:
267267
whatever value is written into the given string.
268268
- `void clear_foo()`: Clears the value of the field. After calling this,
269269
`has_foo()` will return `false` and `foo()` will return the default value.
270-
- `void set_allocated_foo(string* value)`: Sets the `string` object to the
271-
field and frees the previous field value if it exists. If the `string`
272-
pointer is not `NULL`, the message takes ownership of the allocated `string`
273-
object and `has_foo()` will return `true`. The message is free to delete the
274-
allocated `string` object at any time, so references to the object may be
275-
invalidated. Otherwise, if the `value` is `NULL`, the behavior is the same
276-
as calling `clear_foo()`.
277-
- `string* release_foo()`: Releases the ownership of the field and returns the
278-
pointer of the `string` object. After calling this, caller takes the
279-
ownership of the allocated `string` object, `has_foo()` will return `false`,
280-
and `foo()` will return the default value.
270+
- `void set_allocated_foo(string* value)`:
271+
Sets the `string`
272+
object to the field and frees the previous field value if it exists. If the
273+
`string` pointer is not `NULL`, the message takes ownership of the allocated
274+
`string` object and `has_foo()` will return `true`. The message is free to
275+
delete the allocated `string` object at any time, so references to the
276+
object may be invalidated. Otherwise, if the `value` is `NULL`, the behavior
277+
is the same as calling `clear_foo()`.
278+
- `string* release_foo()`:
279+
Releases the
280+
ownership of the field and returns the pointer of the `string` object. After
281+
calling this, caller takes the ownership of the allocated `string` object,
282+
`has_foo()` will return `false`, and `foo()` will return the default value.
281283

282284
### Singular String Fields (proto3) {#proto3_string}
283285

@@ -309,16 +311,18 @@ The compiler will generate the following accessor methods:
309311
return whatever value is written into the given string.
310312
- `void clear_foo()`: Clears the value of the field. After calling this,
311313
`foo()` will return the empty string/empty bytes.
312-
- `void set_allocated_foo(string* value)`: Sets the `string` object to the
313-
field and frees the previous field value if it exists. If the `string`
314-
pointer is not `NULL`, the message takes ownership of the allocated `string`
315-
object. The message is free to delete the allocated `string` object at any
316-
time, so references to the object may be invalidated. Otherwise, if the
317-
`value` is `NULL`, the behavior is the same as calling `clear_foo()`.
318-
- `string* release_foo()`: Releases the ownership of the field and returns the
319-
pointer of the `string` object. After calling this, caller takes the
320-
ownership of the allocated `string` object and `foo()` will return the empty
321-
string/empty bytes.
314+
- `void set_allocated_foo(string* value)`:
315+
Sets the `string`
316+
object to the field and frees the previous field value if it exists. If the
317+
`string` pointer is not `NULL`, the message takes ownership of the allocated
318+
`string` object. The message is free to delete the allocated `string` object
319+
at any time, so references to the object may be invalidated. Otherwise, if
320+
the `value` is `NULL`, the behavior is the same as calling `clear_foo()`.
321+
- `string* release_foo()`:
322+
Releases the
323+
ownership of the field and returns the pointer of the `string` object. After
324+
calling this, caller takes the ownership of the allocated `string` object
325+
and `foo()` will return the empty string/empty bytes.
322326

323327
### Singular Enum Fields (proto2) {#enum_field}
324328

@@ -465,8 +469,8 @@ The compiler will generate the following accessor methods:
465469
- `int foo_size() const`: Returns the number of elements currently in the
466470
field.
467471
- `const string& foo(int index) const`: Returns the element at the given
468-
zero-based index. Calling this method with index outside of [0, foo_size()-1]
469-
yields undefined behavior.
472+
zero-based index. Calling this method with index outside of [0,
473+
foo_size()-1] yields undefined behavior.
470474
- `void set_foo(int index, const string& value)`: Sets the value of the
471475
element at the given zero-based index.
472476
- `void set_foo(int index, const char* value)`: Sets the value of the element
@@ -885,7 +889,8 @@ it is put into a map field as if it is a known enum value.
885889

886890
## Any
887891

888-
Given an [`Any`](/programming-guides/proto3#any) field like this:
892+
Given an [`Any`](/programming-guides/proto3#any) field
893+
like this:
889894

890895
```proto
891896
import "google/protobuf/any.proto";

content/reference/csharp/csharp-generated.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ description: "This topic describes exactly what C# code the protocol buffer comp
1111

1212
This page describes exactly what C\# code the protocol buffer compiler generates
1313
for protocol definitions using `proto3` syntax. You should read the
14-
[proto3 language guide](/programming-guides/proto3) before reading this
15-
document.
14+
[proto3 language guide](/programming-guides/proto3)
15+
before reading this document.
1616

1717
{{% alert title="Note" color="note" %}}
18-
The protobuf compiler can generate C\# interfaces for definitions
19-
using `proto2` syntax starting from release 3.10. Refer to the
20-
[proto2 language guide](/programming-guides/proto) for details of the
21-
semantics of `proto2` definitions, and see `docs/csharp/proto2.md`
18+
The protobuf compiler can generate C\# interfaces for definitions using `proto2`
19+
syntax starting from release 3.10. Refer to the
20+
[proto2 language guide](/programming-guides/proto) for
21+
details of the semantics of `proto2` definitions, and see
22+
`docs/csharp/proto2.md`
2223
([view on GitHub](https://github.com/protocolbuffers/protobuf/blob/master/docs/csharp/proto2.md))
2324
for details on the generated C\# code for proto2.
2425
{{% /alert %}}
@@ -109,7 +110,8 @@ The `namespace` is inferred from the proto's `package`, using the same
109110
conversion rules as the file name. For example, a proto package of
110111
`example.high_score` would result in a namespace of `Example.HighScore`. You can
111112
override the default generated namespace for a particular .proto using the
112-
`csharp_namespace` [file option](/programming-guides/proto3#options).
113+
`csharp_namespace`
114+
[file option](/programming-guides/proto3#options).
113115
114116
Each top-level enum and message results in an enum or class being declared as
115117
members of the namespace. Additionally, a single static partial class is always

content/reference/dart/dart-generated.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ any given protocol definition. Any differences between proto2 and proto3
1414
generated code are highlighted - note that these differences are in the
1515
generated code as described in this document, not the base API, which are the
1616
same in both versions. You should read the
17-
[proto2 language guide](/programming-guides/proto) and/or the
18-
[proto3 language guide](/programming-guides/proto3) before reading this
19-
document.
17+
[proto2 language guide](/programming-guides/proto) and/or
18+
the [proto3 language guide](/programming-guides/proto3)
19+
before reading this document.
2020

2121
## Compiler Invocation {#invocation}
2222

@@ -101,8 +101,8 @@ message in the `.proto` file.
101101

102102
Note that the generated names always use camel-case naming, even if the field
103103
name in the `.proto` file uses lower-case with underscores
104-
([as it should](/programming-guides/style)). The case-conversion works
105-
as follows:
104+
([as it should](/programming-guides/style)). The
105+
case-conversion works as follows:
106106

107107
1. For each underscore in the name, the underscore is removed, and the
108108
following letter is capitalized.
@@ -132,7 +132,8 @@ The compiler will generate the following accessor methods in the message class:
132132
`hasFoo()` will return `false` and `get foo` will return the default value.
133133

134134
For other simple field types, the corresponding Dart type is chosen according to
135-
the [scalar value types table](/programming-guides/proto#scalar).
135+
the
136+
[scalar value types table](/programming-guides/proto#scalar).
136137
For message and enum types, the value type is replaced with the message or enum
137138
class.
138139

@@ -228,7 +229,8 @@ import 'package:fixnum/fixnum.dart';
228229

229230
### Map Fields
230231

231-
Given a [`map`](/programming-guides/proto3#maps) field definition like this:
232+
Given a [`map`](/programming-guides/proto3#maps) field
233+
definition like this:
232234

233235
```proto
234236
map<int32, int32> map_field = 1;
@@ -242,7 +244,8 @@ The compiler will generate the following getter:
242244

243245
## Any
244246

245-
Given an [`Any`](/programming-guides/proto3#any) field like this:
247+
Given an [`Any`](/programming-guides/proto3#any) field
248+
like this:
246249

247250
```proto
248251
import "google/protobuf/any.proto";
@@ -285,7 +288,8 @@ and unpack the `Any`'s values:
285288

286289
## Oneof
287290

288-
Given a [`oneof`](/programming-guides/proto3#oneof) definition like this:
291+
Given a [`oneof`](/programming-guides/proto3#oneof)
292+
definition like this:
289293

290294
```proto
291295
message Foo {
@@ -383,8 +387,8 @@ The protocol buffer compiler will generate a class called `Bar`, which extends
383387
## Extensions (proto2 only) {#extension}
384388

385389
Given a file `foo_test.proto` including a message with an
386-
[extension range](/programming-guides/proto#extensions) and a top-level
387-
extension definition:
390+
[extension range](/programming-guides/proto#extensions)
391+
and a top-level extension definition:
388392

389393
```proto
390394
message Foo {

0 commit comments

Comments
 (0)