Skip to content

Commit 4ecd7cf

Browse files
Protocol Buffer TeamLogofile
authored andcommitted
Project import generated by Copybara.
PiperOrigin-RevId: 500192045 Change-Id: Ia12247cacd1ef63f7d154b294d6f11592f3c9c7a
1 parent 0a8fabf commit 4ecd7cf

File tree

8 files changed

+100
-78
lines changed

8 files changed

+100
-78
lines changed

config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ github_project_repo = "https://github.com/protocolbuffers/protobuf"
124124
# github_branch= "main"
125125

126126
# Google Custom Search Engine ID. Remove or comment out to disable search.
127-
gcs_engine_id = "d72aa9b2712488cc3"
127+
# gcs_engine_id = "d72aa9b2712488cc3"
128128

129129
# Enable Algolia DocSearch
130130
algolia_docsearch = false
131131

132132
# Enable Lunr.js offline search
133-
offlineSearch = false
133+
offlineSearch = true
134134

135135
# Enable syntax highlighting and copy buttons on code blocks with Prism
136136
prism_syntax_highlighting = false

content/programming-guides/encoding.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ concatenation) even if you do not know their types.
361361

362362
### Packed Repeated Fields {#packed}
363363

364-
Starting in v2.1.0, `repeated` fields of scalar integer type can be declared as
364+
Starting in v2.1.0, `repeated` fields of scalar type can be declared as
365365
"packed". In proto2 this is done with the `[packed=true]`, but in proto3 it is
366366
the default.
367367

@@ -474,10 +474,10 @@ Field numbers may be declared in any order in a `.proto` file. The order chosen
474474
has no effect on how the messages are serialized.
475475

476476
When a message is serialized, there is no guaranteed order for how its known or
477-
[unknown fields](/programming-guides/proto#updating) will be written.
478-
Serialization order is an implementation detail, and the details of any
479-
particular implementation may change in the future. Therefore, protocol buffer
480-
parsers must be able to parse fields in any order.
477+
[unknown fields](/programming-guides/proto#updating) will
478+
be written. Serialization order is an implementation detail, and the details of
479+
any particular implementation may change in the future. Therefore, protocol
480+
buffer parsers must be able to parse fields in any order.
481481

482482
### Implications
483483

content/programming-guides/proto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ projects we know about, see the
13121312
Individual declarations in a `.proto` file can be annotated with a number of
13131313
*options*. Options do not change the overall meaning of a declaration, but may
13141314
affect the way it is handled in a particular context. The complete list of
1315-
available options is defined in `google/protobuf/descriptor.proto`.
1315+
available options is defined in [`/google/protobuf/descriptor.proto`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
13161316
13171317
Some options are file-level options, meaning they should be written at the
13181318
top-level scope, not inside any message, enum, or service definition. Some

content/programming-guides/proto3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ A proto3 JSON implementation may provide the following options:
14731473
Individual declarations in a `.proto` file can be annotated with a number of
14741474
*options*. Options do not change the overall meaning of a declaration, but may
14751475
affect the way it is handled in a particular context. The complete list of
1476-
available options is defined in `google/protobuf/descriptor.proto`.
1476+
available options is defined in [`/google/protobuf/descriptor.proto`](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/descriptor.proto).
14771477

14781478
Some options are file-level options, meaning they should be written at the
14791479
top-level scope, not inside any message, enum, or service definition. Some

content/reference/cpp/arenas.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ exactly what C++ code the protocol buffer compiler generates in addition to the
1515
code described in the
1616
[C++ Generated Code Guide](/reference/cpp/cpp-generated)
1717
when arena allocation is enabled. It assumes that you are familiar with the
18-
material in the [language guide](/programming-guides/proto) and the
18+
material in the
19+
[language guide](/programming-guides/proto) and the
1920
[C++ Generated Code Guide](/reference/cpp/cpp-generated).
2021

2122
## Why Use Arena Allocation? {#why}
@@ -76,7 +77,7 @@ can see a more extensive [example](#example) at the end of the document.
7677
## Arena Class API {#arenaclass}
7778

7879
You create message objects on the arena using the
79-
[`google::protobuf::Arena`](/reference/cpp/api-docs/google.protobuf.arena)
80+
[`google::protobuf::Arena`](/reference/cpp/api-docs/google.protobuf.arena.md)
8081
class. This class implements the following public methods.
8182

8283
### Constructors {#constructors}
@@ -205,12 +206,12 @@ allocation.
205206
unspecified state.
206207
- `void Swap(Message* other)`: If both messages to be swapped are not on
207208
arenas or are on the *same* arena,
208-
[`Swap()`](/reference/cpp/cpp-generated#message) behaves
209-
as it does without having arena allocation enabled: it efficiently swaps the
210-
message objects' contents, usually via cheap pointer swaps and avoiding
211-
copies at all costs. However, if only one message is on an arena, or the
212-
messages are on different arenas, `Swap()` performs *deep copies* of the
213-
underlying data. This new behavior is necessary because otherwise the
209+
[`Swap()`](/reference/cpp/cpp-generated#message)
210+
behaves as it does without having arena allocation enabled: it efficiently
211+
swaps the message objects' contents, almost exclusively through cheap
212+
pointer swaps, avoiding copies. However, if only one message is on an arena,
213+
or the messages are on different arenas, `Swap()` performs *deep copies* of
214+
the underlying data. This new behavior is necessary because otherwise the
214215
swapped sub-objects could have differing lifetimes, leading potentially to
215216
use-after-free bugs.
216217
- `Message* New(Arena* arena)`: An alternate override for the standard `New()`
@@ -292,8 +293,8 @@ allocation is enabled. Otherwise, accessor methods just use the
292293

293294
Currently, string fields store their data on the heap even when their parent
294295
message is on the arena. Because of this, string accessor methods use the
295-
[default behavior](/reference/cpp/cpp-generated#string) even
296-
when arena allocation is enabled.
296+
[default behavior](/reference/cpp/cpp-generated#string)
297+
even when arena allocation is enabled.
297298

298299
### Repeated Fields {#arenarepeated}
299300

@@ -339,13 +340,24 @@ methods when arena allocation is enabled.
339340
occurs. This means that after the swap, each repeated field object holds an
340341
array on its own arena or on the heap, as appropriate.
341342
- `void AddAllocated(SubMessageType* value)`: Checks that the provided message
342-
object is on the same arena as the repeated field's arena pointer. If it is
343-
on the same arena, then the object pointer is added directly to the
344-
underlying array. Otherwise, a copy is made, the original is freed if it was
345-
heap-allocated, and the copy is placed on the array. This maintains the
346-
invariant that all objects pointed to by a repeated field are in the same
347-
ownership domain (heap or specific arena) as indicated by the repeated
348-
field's arena pointer.
343+
object is on the same arena as the repeated field's arena pointer.
344+
345+
* The source and destination are both arena-allocated and on the same
346+
arena: the object pointer is added directly to the underlying array.
347+
* The source and destination are both arena-allocated and on different
348+
arenas: a copy is made, the original is freed if it was heap-allocated,
349+
and the copy is placed on the array.
350+
* The source is heap-allocated and the destination is arena-allocated: No
351+
copy is made.
352+
* The source is arena-allocated and the destination is heap-allocated: A
353+
copy is made and placed on the array.
354+
* Both source and destination are heap allocated: The object pointer is
355+
added directly to the underlying array.
356+
357+
This maintains the invariant that all objects pointed to by a repeated field
358+
are in the same ownership domain (heap or specific arena) as indicated by
359+
the repeated field's arena pointer.
360+
349361
- `SubMessageType* ReleaseLast()`: Returns a heap-allocated message equivalent
350362
to the last message in the repeated field, removing it from the repeated
351363
field. If the repeated field itself has a NULL arena pointer (and thus, all
@@ -355,23 +367,27 @@ methods when arena allocation is enabled.
355367
heap-allocated and returns that copy. In both cases, the caller receives
356368
ownership of a heap-allocated object and is responsible for deleting the
357369
object.
370+
358371
- `void UnsafeArenaAddAllocated(SubMessageType* value)`: Like
359372
`AddAllocated()`, but does not perform heap/arena checks or any message
360373
copies. It adds the provided pointer directly to the internal array of
361374
pointers for this repeated field. See
362375
[allocated/release patterns](#set-allocated) for details on safe ways to use
363376
this.
377+
364378
- `SubMessageType* UnsafeArenaReleaseLast()`: Like `ReleaseLast()` but
365379
performs no copies, even if the repeated field has a non-NULL arena pointer.
366380
Instead, it directly returns the pointer to the object as it was in the
367381
repeated field. See [allocated/release patterns](#set-allocated) for details
368382
on safe ways to use this.
383+
369384
- `void ExtractSubrange(int start, int num, SubMessageType** elements)`:
370385
Removes `num` elements from the repeated field, starting from index `start`,
371386
and returns them in `elements` if it is not NULL. If the repeated field is
372387
on an arena, and elements are being returned, the elements are copied to the
373388
heap first. In both cases (arena or no arena), the caller owns the returned
374389
objects on the heap.
390+
375391
- `void UnsafeArenaExtractSubrange(int start, int num, SubMessageType**
376392
elements)`: Removes `num` elements from the repeated field, starting from
377393
index `start`, and returns them in `elements` if it is not NULL. Unlike

content/reference/java/java-generated.md

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ proto3 generated code are highlighted—note that these differences are in
1515
the 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
Note that no Java protocol buffer methods accept or return nulls unless
2222
otherwise specified.
@@ -165,9 +165,9 @@ then `Foo` will include fast implementations of all methods, but will implement
165165
the `MessageLite` interface, which only contains a subset of the methods of
166166
`Message`. In particular, it does not support descriptors or reflection.
167167
However, in this mode, the generated code only needs to link against
168-
`libprotobuf-lite.jar` instead of `libprotobuf.jar`. The "lite" library is
169-
much smaller than the full library, and is more appropriate for
170-
resource-constrained systems such as mobile phones.
168+
`libprotobuf-lite.jar` instead of `libprotobuf.jar`. The "lite" library is much
169+
smaller than the full library, and is more appropriate for resource-constrained
170+
systems such as mobile phones.
171171

172172
The `Message` interface defines methods that let you check, manipulate, read, or
173173
write the entire message. In addition to these methods, the `Foo` class defines
@@ -288,8 +288,8 @@ that modify the value are defined in the builder only.
288288

289289
Note that method names always use camel-case naming, even if the field name in
290290
the `.proto` file uses lower-case with underscores
291-
([as it should](/programming-guides/style)). The case-conversion works
292-
as follows:
291+
([as it should](/programming-guides/style)). The
292+
case-conversion works as follows:
293293

294294
1. For each underscore in the name, the underscore is removed, and the
295295
following letter is capitalized.
@@ -329,7 +329,8 @@ The compiler will generate the following methods only in the message's builder:
329329
`hasFoo()` will return `false` and `getFoo()` will return the default value.
330330

331331
For other simple field types, the corresponding Java type is chosen according to
332-
the [scalar value types table](/programming-guides/proto#scalar).
332+
the
333+
[scalar value types table](/programming-guides/proto#scalar).
333334
For message and enum types, the value type is replaced with the message or enum
334335
class.
335336

@@ -376,7 +377,8 @@ The compiler will generate the following methods only in the message's builder:
376377
`getFoo()` will return the default value for the field's type.
377378

378379
For other simple field types, the corresponding Java type is chosen according to
379-
the [scalar value types table](/programming-guides/proto#scalar).
380+
the
381+
[scalar value types table](/programming-guides/proto#scalar).
380382
For message and enum types, the value type is replaced with the message or enum
381383
class.
382384

@@ -427,88 +429,89 @@ the generated [enum type](#enum).
427429
For this field definition:
428430

429431
```proto
430-
repeated string foo = 1;
432+
repeated string foos = 1;
431433
```
432434

433435
The compiler will generate the following accessor methods in both the message
434436
class and its builder:
435437

436-
- `int getFooCount()`: Returns the number of elements currently in the field.
437-
- `String getFoo(int index)`: Returns the element at the given zero-based
438+
- `int getFoosCount()`: Returns the number of elements currently in the field.
439+
- `String getFoos(int index)`: Returns the element at the given zero-based
438440
index.
439-
- `ProtocolStringList getFooList()`: Returns the entire field as a
441+
- `ProtocolStringList getFoosList()`: Returns the entire field as a
440442
`ProtocolStringList`. If the field is not set, returns an empty list.
441443

442444
The compiler will generate the following methods only in the message's builder:
443445

444-
- `Builder setFoo(int index, String value)`: Sets the value of the element at
446+
- `Builder setFoos(int index, String value)`: Sets the value of the element at
445447
the given zero-based index.
446-
- `Builder addFoo(String value)`: Appends a new element to the field with the
448+
- `Builder addFoos(String value)`: Appends a new element to the field with the
447449
given value.
448-
- `Builder addAllFoo(Iterable<? extends String> value)`: Appends all elements
450+
- `Builder addAllFoos(Iterable<? extends String> value)`: Appends all elements
449451
in the given `Iterable` to the field.
450-
- `Builder clearFoo()`: Removes all elements from the field. After calling
451-
this, `getFooCount()` will return zero.
452+
- `Builder clearFoos()`: Removes all elements from the field. After calling
453+
this, `getFoosCount()` will return zero.
452454

453455
For other simple field types, the corresponding Java type is chosen according to
454-
the [scalar value types table](/programming-guides/proto#scalar).
456+
the
457+
[scalar value types table](/programming-guides/proto#scalar).
455458
For message and enum types, the type is the message or enum class.
456459

457460
#### Repeated Embedded Message Fields
458461

459-
For message types, `setFoo()` and `addFoo()` also accept an instance of the
462+
For message types, `setFoos()` and `addFoos()` also accept an instance of the
460463
message's builder type as the parameter. This is just a shortcut which is
461464
equivalent to calling `.build()` on the builder and passing the result to the
462465
method. There is also an additional generated method:
463466

464-
- `Builder addFoo(int index, Field value)`: Inserts a new element at the given
465-
zero-based index. Shifts the element currently at that position (if any) and
466-
any subsequent elements to the right (adds one to their indices).
467+
- `Builder addFoos(int index, Field value)`: Inserts a new element at the
468+
given zero-based index. Shifts the element currently at that position (if
469+
any) and any subsequent elements to the right (adds one to their indices).
467470

468471
In addition, the compiler generates the following additional accessor methods in
469472
both the message class and its builder for message types, allowing you to access
470473
the relevant sub-builders:
471474

472-
- `FooOrBuilder getFooOrBuilder(int index)`: Returns the builder for the
475+
- `FooOrBuilder getFoosOrBuilder(int index)`: Returns the builder for the
473476
specified element, if it already exists, or throws
474477
`IndexOutOfBoundsException` if not. If this is called from a message class,
475478
it will always return a message (or throw an exception) rather than a
476479
builder. Calling this method on builders will not create a sub-builder for
477480
the field.
478-
- `List<FooOrBuilder> getFooOrBuilderList()`: Returns the entire field as an
481+
- `List<FooOrBuilder> getFoosOrBuilderList()`: Returns the entire field as an
479482
unmodifiable list of builders (if available) or messages if not. If this is
480483
called from a message class, it will always return an immutable list of
481484
messages rather than an unmodifiable list of builders.
482485

483486
The compiler will generate the following methods only in the message's builder:
484487

485-
- `Builder getFooBuilder(int index)`: Returns the builder for the element at
488+
- `Builder getFoosBuilder(int index)`: Returns the builder for the element at
486489
the specified index, or throws `IndexOutOfBoundsException` if the index is
487490
out of bounds.
488-
- `Builder addFooBuilder(int index)`: Inserts and returns a builder for a
491+
- `Builder addFoosBuilder(int index)`: Inserts and returns a builder for a
489492
default message instance at the specified index. The existing entries are
490493
shifted to higher indices to make room for the inserted builder.
491-
- `Builder addFooBuilder()`: Appends and returns a builder for a default
494+
- `Builder addFoosBuilder()`: Appends and returns a builder for a default
492495
message instance.
493-
- `Builder removeFoo(int index)`: Removes the element at the given zero-based
496+
- `Builder removeFoos(int index)`: Removes the element at the given zero-based
494497
index.
495-
- `List<Builder> getFooBuilderList()`: Returns the entire field as an
498+
- `List<Builder> getFoosBuilderList()`: Returns the entire field as an
496499
unmodifiable list of builders.
497500

498501
#### Repeated Enum Fields (proto3 only)
499502

500503
The compiler will generate the following additional methods in both the message
501504
class and its builder:
502505

503-
- `int getFooValue(int index)`: Returns the integer value of the enum at the
506+
- `int getFoosValue(int index)`: Returns the integer value of the enum at the
504507
specified index.
505-
- `List<java.lang.Integer> getFooValueList()`: Returns the entire field as a
508+
- `List<java.lang.Integer> getFoosValueList()`: Returns the entire field as a
506509
list of Integers.
507510

508511
The compiler will generate the following additional method only in the message's
509512
builder:
510513

511-
- `Builder setFooValue(int index, int value)`: Sets the integer value of the
514+
- `Builder setFoosValue(int index, int value)`: Sets the integer value of the
512515
enum at the specified index.
513516

514517
#### Name Conflicts
@@ -520,15 +523,15 @@ number appended to the end.
520523
For these field definitions:
521524

522525
```proto
523-
int32 foo_count = 1;
524-
repeated string foo = 2;
526+
int32 foos_count = 1;
527+
repeated string foos = 2;
525528
```
526529

527530
The compiler will first rename them to the following:
528531

529532
```proto
530-
int32 foo_count_1 = 1;
531-
repeated string foo_2 = 2;
533+
int32 foos_count_1 = 1;
534+
repeated string foos_2 = 2;
532535
```
533536

534537
The accessor methods will subsequently be generated as described above.
@@ -564,7 +567,8 @@ The compiler will generate the following methods only in the message's builder:
564567
`getExampleNameCase()` will return `EXAMPLENAME_NOT_SET`.
565568

566569
For other simple field types, the corresponding Java type is chosen according to
567-
the [scalar value types table](/programming-guides/proto#scalar).
570+
the
571+
[scalar value types table](/programming-guides/proto#scalar).
568572
For message and enum types, the value type is replaced with the message or enum
569573
class.
570574

@@ -602,7 +606,8 @@ The compiler will generate the following methods only in the message's builder:
602606

603607
## Any
604608

605-
Given an [`Any`](/programming-guides/proto3#any) field like this:
609+
Given an [`Any`](/programming-guides/proto3#any) field
610+
like this:
606611

607612
```proto
608613
import "google/protobuf/any.proto";
@@ -994,8 +999,8 @@ sends requests to a particular `BlockingRpcChannel`.
994999
## Plugin Insertion Points {#plugins}
9951000

9961001
[Code generator plugins](/reference/cpp/api-docs/google.protobuf.compiler.plugin.pb)
997-
that want to extend the output of the Java code generator may insert code of
998-
the following types using the given insertion point names.
1002+
that want to extend the output of the Java code generator may insert code of the
1003+
following types using the given insertion point names.
9991004

10001005
- `outer_class_scope`: Member declarations that belong in the file's wrapper
10011006
class.

0 commit comments

Comments
 (0)