Skip to content

Commit d933980

Browse files
authored
Merge pull request #173 from Logofile/sync
Documentation update
2 parents 52f3c74 + 3fe2759 commit d933980

File tree

5 files changed

+138
-18
lines changed

5 files changed

+138
-18
lines changed

content/getting-started/pythontutorial.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,40 @@ descriptors for all your messages, enums, and fields, and some mysteriously
209209
empty classes, one for each message type:
210210

211211
```python
212-
class Person(message.Message):
213-
__metaclass__ = reflection.GeneratedProtocolMessageType
214-
215-
class PhoneNumber(message.Message):
216-
__metaclass__ = reflection.GeneratedProtocolMessageType
217-
DESCRIPTOR = _PERSON_PHONENUMBER
218-
DESCRIPTOR = _PERSON
219-
220-
class AddressBook(message.Message):
221-
__metaclass__ = reflection.GeneratedProtocolMessageType
222-
DESCRIPTOR = _ADDRESSBOOK
212+
import google3
213+
from google.protobuf import descriptor as _descriptor
214+
from google.protobuf import descriptor_pool as _descriptor_pool
215+
from google.protobuf import runtime_version as _runtime_version
216+
from google.protobuf import symbol_database as _symbol_database
217+
from google.protobuf.internal import builder as _builder
218+
_runtime_version.ValidateProtobufRuntimeVersion(
219+
_runtime_version.Domain.GOOGLE_INTERNAL,
220+
0,
221+
20240502,
222+
0,
223+
'',
224+
'main.proto'
225+
)
226+
# @@protoc_insertion_point(imports)
227+
228+
_sym_db = _symbol_database.Default()
229+
230+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nmain.proto\x12\x08tutorial\"\xa3\x02\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\n\n\x02id\x18\x02 \x01(\x05\x12\r\n\x05\x65mail\x18\x03 \x01(\t\x12,\n\x06phones\x18\x04 \x03(\x0b\x32\x1c.tutorial.Person.PhoneNumber\x1aX\n\x0bPhoneNumber\x12\x0e\n\x06number\x18\x01 \x01(\t\x12\x39\n\x04type\x18\x02 \x01(\x0e\x32\x1a.tutorial.Person.PhoneType:\x0fPHONE_TYPE_HOME\"h\n\tPhoneType\x12\x1a\n\x16PHONE_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11PHONE_TYPE_MOBILE\x10\x01\x12\x13\n\x0fPHONE_TYPE_HOME\x10\x02\x12\x13\n\x0fPHONE_TYPE_WORK\x10\x03\"/\n\x0b\x41\x64\x64ressBook\x12 \n\x06people\x18\x01 \x03(\x0b\x32\x10.tutorial.Person')
231+
232+
_globals = globals()
233+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
234+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google3.main_pb2', _globals)
235+
if not _descriptor._USE_C_DESCRIPTORS:
236+
DESCRIPTOR._loaded_options = None
237+
_globals['_PERSON']._serialized_start=25
238+
_globals['_PERSON']._serialized_end=316
239+
_globals['_PERSON_PHONENUMBER']._serialized_start=122
240+
_globals['_PERSON_PHONENUMBER']._serialized_end=210
241+
_globals['_PERSON_PHONETYPE']._serialized_start=212
242+
_globals['_PERSON_PHONETYPE']._serialized_end=316
243+
_globals['_ADDRESSBOOK']._serialized_start=318
244+
_globals['_ADDRESSBOOK']._serialized_end=365
245+
# @@protoc_insertion_point(module_scope)
223246
```
224247
225248
The important line in each class is `__metaclass__ =
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
+++
2+
title = "Proto Limits"
3+
weight = 45
4+
description = "Covers the limits to number of supported elements in proto schemas."
5+
type = "docs"
6+
+++
7+
8+
This topic documents the limits to the number of supported elements (fields,
9+
enum values, and so on) in proto schemas.
10+
11+
## Number of Fields {#fields}
12+
13+
Message with only singular proto fields (such as Boolean):
14+
15+
* ~2100 fields (proto2)
16+
* ~3100 (proto3 without using optional fields)
17+
18+
Empty message extended by singular fields (such as Boolean):
19+
20+
* ~4100 fields (proto2)
21+
22+
Extensions are supported
23+
[only by proto2](/programming-guides/version-comparison#extensionsany).
24+
25+
To test this limitation, create a proto message with more than the upper bound
26+
number of fields and compile using a Java proto rule. The limit comes from JVM
27+
specs.
28+
29+
## Number of Values in an Enum {#enum}
30+
31+
The lowest limit is ~1700 values, in Java. Other languages have different
32+
limits.
33+
34+
## Total Size of the Message {#total}
35+
36+
Any proto in serialized form must be <2GiB, as that is the maximum size
37+
supported by all implementations. It's recommended to bound request and response
38+
sizes.
39+
40+
## Depth Limit for Proto Unmarshaling {#depth}
41+
42+
* Java: 100
43+
* C++: 100
44+
* Go:
45+
10000
46+
(there is a plan to reduce this to 100)
47+
48+
If you try to unmarshal a message that is nested deeper than the depth limit,
49+
the unmarshaling will fail.

content/programming-guides/proto2.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,24 @@ in version 3.5 we reintroduced the preservation of unknown fields to match the
947947
proto2 behavior. In versions 3.5 and later, unknown fields are retained during
948948
parsing and included in the serialized output.
949949

950+
### Retaining Unknown Fields {#retaining}
951+
952+
Some actions can cause unknown fields to be lost. For example, if you do one of
953+
the following, unknown fields are lost:
954+
955+
* Serialize a proto to JSON.
956+
* Iterate over all of the fields in a message to populate a new message.
957+
958+
To avoid losing unknown fields, do the following:
959+
960+
* Use binary; avoid using text formats for data exchange.
961+
* Use message-oriented APIs, such as `CopyFrom()` and `MergeFrom()`, to copy data
962+
rather than copying field-by-field
963+
964+
TextFormat is a bit of a special case. Serializing to TextFormat prints unknown
965+
fields using their field numbers. But parsing TextFormat data back into a binary
966+
proto fails if there are entries that use field numbers.
967+
950968
## Extensions {#extensions}
951969

952970
An extension is a field defined outside of its container message; usually in a

content/programming-guides/proto3.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ automatically generated class:
335335
<th>C# Type</th>
336336
<th>PHP Type</th>
337337
<th>Dart Type</th>
338+
<th>Rust Type</th>
338339
</tr>
339340
<tr>
340341
<td>double</td>
@@ -347,6 +348,7 @@ automatically generated class:
347348
<td>double</td>
348349
<td>float</td>
349350
<td>double</td>
351+
<td>f64</td>
350352
</tr>
351353
<tr>
352354
<td>float</td>
@@ -359,6 +361,7 @@ automatically generated class:
359361
<td>float</td>
360362
<td>float</td>
361363
<td>double</td>
364+
<td>f32</td>
362365
</tr>
363366
<tr>
364367
<td>int32</td>
@@ -373,6 +376,7 @@ automatically generated class:
373376
<td>int</td>
374377
<td>integer</td>
375378
<td>int</td>
379+
<td>i32</td>
376380
</tr>
377381
<tr>
378382
<td>int64</td>
@@ -387,6 +391,7 @@ automatically generated class:
387391
<td>long</td>
388392
<td>integer/string<sup>[6]</sup></td>
389393
<td>Int64</td>
394+
<td>i64</td>
390395
</tr>
391396
<tr>
392397
<td>uint32</td>
@@ -399,6 +404,7 @@ automatically generated class:
399404
<td>uint</td>
400405
<td>integer</td>
401406
<td>int</td>
407+
<td>u32</td>
402408
</tr>
403409
<tr>
404410
<td>uint64</td>
@@ -411,6 +417,7 @@ automatically generated class:
411417
<td>ulong</td>
412418
<td>integer/string<sup>[6]</sup></td>
413419
<td>Int64</td>
420+
<td>u64</td>
414421
</tr>
415422
<tr>
416423
<td>sint32</td>
@@ -424,6 +431,7 @@ automatically generated class:
424431
<td>int</td>
425432
<td>integer</td>
426433
<td>int</td>
434+
<td>i32</td>
427435
</tr>
428436
<tr>
429437
<td>sint64</td>
@@ -437,6 +445,7 @@ automatically generated class:
437445
<td>long</td>
438446
<td>integer/string<sup>[6]</sup></td>
439447
<td>Int64</td>
448+
<td>i64</td>
440449
</tr>
441450
<tr>
442451
<td>fixed32</td>
@@ -450,6 +459,7 @@ automatically generated class:
450459
<td>uint</td>
451460
<td>integer</td>
452461
<td>int</td>
462+
<td>u32</td>
453463
</tr>
454464
<tr>
455465
<td>fixed64</td>
@@ -463,6 +473,7 @@ automatically generated class:
463473
<td>ulong</td>
464474
<td>integer/string<sup>[6]</sup></td>
465475
<td>Int64</td>
476+
<td>u64</td>
466477
</tr>
467478
<tr>
468479
<td>sfixed32</td>
@@ -475,6 +486,7 @@ automatically generated class:
475486
<td>int</td>
476487
<td>integer</td>
477488
<td>int</td>
489+
<td>i32</td>
478490
</tr>
479491
<tr>
480492
<td>sfixed64</td>
@@ -487,6 +499,7 @@ automatically generated class:
487499
<td>long</td>
488500
<td>integer/string<sup>[6]</sup></td>
489501
<td>Int64</td>
502+
<td>i64</td>
490503
</tr>
491504
<tr>
492505
<td>bool</td>
@@ -499,6 +512,7 @@ automatically generated class:
499512
<td>bool</td>
500513
<td>boolean</td>
501514
<td>bool</td>
515+
<td>bool</td>
502516
</tr>
503517
<tr>
504518
<td>string</td>
@@ -512,6 +526,7 @@ automatically generated class:
512526
<td>string</td>
513527
<td>string</td>
514528
<td>String</td>
529+
<td>ProtoString</td>
515530
</tr>
516531
<tr>
517532
<td>bytes</td>
@@ -524,6 +539,7 @@ automatically generated class:
524539
<td>ByteString</td>
525540
<td>string</td>
526541
<td>List<int></td>
542+
<td>ProtoBytes</td>
527543
</tr>
528544
</tbody>
529545
</table>
@@ -925,6 +941,24 @@ unknown fields in the old binary.
925941
Proto3 messages preserve unknown fields and includes them during parsing and in
926942
the serialized output, which matches proto2 behavior.
927943

944+
### Retaining Unknown Fields {#retaining}
945+
946+
Some actions can cause unknown fields to be lost. For example, if you do one of
947+
the following, unknown fields are lost:
948+
949+
* Serialize a proto to JSON.
950+
* Iterate over all of the fields in a message to populate a new message.
951+
952+
To avoid losing unknown fields, do the following:
953+
954+
* Use binary; avoid using text formats for data exchange.
955+
* Use message-oriented APIs, such as `CopyFrom()` and `MergeFrom()`, to copy data
956+
rather than copying field-by-field
957+
958+
TextFormat is a bit of a special case. Serializing to TextFormat prints unknown
959+
fields using their field numbers. But parsing TextFormat data back into a binary
960+
proto fails if there are entries that use field numbers.
961+
928962
## Any {#any}
929963

930964
The `Any` message type lets you use messages as embedded types without having

content/reference/cpp/cpp-generated.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,9 @@ corresponding C++ type according to the
249249

250250
### Implicit Presence Numeric Fields (proto3) {#implicit-numeric}
251251

252-
For these field definitions:
252+
For the below field definition:
253253

254254
```proto
255-
optional int32 foo = 1;
256255
int32 foo = 1; // no field label specified, defaults to implicit presence.
257256
```
258257

@@ -322,12 +321,10 @@ The compiler will generate the following accessor methods:
322321

323322
### Implicit Presence String/Bytes Fields (proto3) {#implicit-string}
324323

325-
For any of these field definitions:
324+
For either of these field definitions:
326325

327326
```proto
328-
optional string foo = 1;
329327
string foo = 1; // no field label specified, defaults to implicit presence.
330-
optional bytes foo = 1;
331328
bytes foo = 1;
332329
```
333330

@@ -440,10 +437,9 @@ enum Bar {
440437
}
441438
```
442439

443-
For these field definitions:
440+
For this field definition:
444441

445442
```proto
446-
optional Bar foo = 1;
447443
Bar foo = 1; // no field label specified, defaults to implicit presence.
448444
```
449445

0 commit comments

Comments
 (0)