betterproto2-compiler 0.2.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- betterproto2_compiler/__init__.py +0 -0
- betterproto2_compiler/casing.py +140 -0
- betterproto2_compiler/compile/__init__.py +0 -0
- betterproto2_compiler/compile/importing.py +180 -0
- betterproto2_compiler/compile/naming.py +21 -0
- betterproto2_compiler/known_types/__init__.py +14 -0
- betterproto2_compiler/known_types/any.py +36 -0
- betterproto2_compiler/known_types/duration.py +25 -0
- betterproto2_compiler/known_types/timestamp.py +45 -0
- betterproto2_compiler/lib/__init__.py +0 -0
- betterproto2_compiler/lib/google/__init__.py +0 -0
- betterproto2_compiler/lib/google/protobuf/__init__.py +3338 -0
- betterproto2_compiler/lib/google/protobuf/compiler/__init__.py +235 -0
- betterproto2_compiler/lib/message_pool.py +3 -0
- betterproto2_compiler/plugin/__init__.py +3 -0
- betterproto2_compiler/plugin/__main__.py +3 -0
- betterproto2_compiler/plugin/compiler.py +70 -0
- betterproto2_compiler/plugin/main.py +47 -0
- betterproto2_compiler/plugin/models.py +643 -0
- betterproto2_compiler/plugin/module_validation.py +156 -0
- betterproto2_compiler/plugin/parser.py +272 -0
- betterproto2_compiler/plugin/plugin.bat +2 -0
- betterproto2_compiler/plugin/typing_compiler.py +163 -0
- betterproto2_compiler/py.typed +0 -0
- betterproto2_compiler/settings.py +9 -0
- betterproto2_compiler/templates/header.py.j2 +59 -0
- betterproto2_compiler/templates/template.py.j2 +258 -0
- betterproto2_compiler-0.2.0.dist-info/LICENSE.md +22 -0
- betterproto2_compiler-0.2.0.dist-info/METADATA +35 -0
- betterproto2_compiler-0.2.0.dist-info/RECORD +32 -0
- betterproto2_compiler-0.2.0.dist-info/WHEEL +4 -0
- betterproto2_compiler-0.2.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,3338 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# sources: google/protobuf/any.proto, google/protobuf/api.proto, google/protobuf/descriptor.proto, google/protobuf/duration.proto, google/protobuf/empty.proto, google/protobuf/field_mask.proto, google/protobuf/source_context.proto, google/protobuf/struct.proto, google/protobuf/timestamp.proto, google/protobuf/type.proto, google/protobuf/wrappers.proto
|
3
|
+
# plugin: python-betterproto2
|
4
|
+
# This file has been @generated
|
5
|
+
|
6
|
+
__all__ = (
|
7
|
+
"Edition",
|
8
|
+
"ExtensionRangeOptionsVerificationState",
|
9
|
+
"FeatureSetEnumType",
|
10
|
+
"FeatureSetFieldPresence",
|
11
|
+
"FeatureSetJsonFormat",
|
12
|
+
"FeatureSetMessageEncoding",
|
13
|
+
"FeatureSetRepeatedFieldEncoding",
|
14
|
+
"FeatureSetUtf8Validation",
|
15
|
+
"FieldCardinality",
|
16
|
+
"FieldKind",
|
17
|
+
"FieldDescriptorProtoLabel",
|
18
|
+
"FieldDescriptorProtoType",
|
19
|
+
"FieldOptionsCType",
|
20
|
+
"FieldOptionsJsType",
|
21
|
+
"FieldOptionsOptionRetention",
|
22
|
+
"FieldOptionsOptionTargetType",
|
23
|
+
"FileOptionsOptimizeMode",
|
24
|
+
"GeneratedCodeInfoAnnotationSemantic",
|
25
|
+
"MethodOptionsIdempotencyLevel",
|
26
|
+
"NullValue",
|
27
|
+
"Syntax",
|
28
|
+
"Any",
|
29
|
+
"Api",
|
30
|
+
"BoolValue",
|
31
|
+
"BytesValue",
|
32
|
+
"DescriptorProto",
|
33
|
+
"DescriptorProtoExtensionRange",
|
34
|
+
"DescriptorProtoReservedRange",
|
35
|
+
"DoubleValue",
|
36
|
+
"Duration",
|
37
|
+
"Empty",
|
38
|
+
"Enum",
|
39
|
+
"EnumDescriptorProto",
|
40
|
+
"EnumDescriptorProtoEnumReservedRange",
|
41
|
+
"EnumOptions",
|
42
|
+
"EnumValue",
|
43
|
+
"EnumValueDescriptorProto",
|
44
|
+
"EnumValueOptions",
|
45
|
+
"ExtensionRangeOptions",
|
46
|
+
"ExtensionRangeOptionsDeclaration",
|
47
|
+
"FeatureSet",
|
48
|
+
"FeatureSetDefaults",
|
49
|
+
"FeatureSetDefaultsFeatureSetEditionDefault",
|
50
|
+
"Field",
|
51
|
+
"FieldDescriptorProto",
|
52
|
+
"FieldMask",
|
53
|
+
"FieldOptions",
|
54
|
+
"FieldOptionsEditionDefault",
|
55
|
+
"FileDescriptorProto",
|
56
|
+
"FileDescriptorSet",
|
57
|
+
"FileOptions",
|
58
|
+
"FloatValue",
|
59
|
+
"GeneratedCodeInfo",
|
60
|
+
"GeneratedCodeInfoAnnotation",
|
61
|
+
"Int32Value",
|
62
|
+
"Int64Value",
|
63
|
+
"ListValue",
|
64
|
+
"MessageOptions",
|
65
|
+
"Method",
|
66
|
+
"MethodDescriptorProto",
|
67
|
+
"MethodOptions",
|
68
|
+
"Mixin",
|
69
|
+
"OneofDescriptorProto",
|
70
|
+
"OneofOptions",
|
71
|
+
"Option",
|
72
|
+
"ServiceDescriptorProto",
|
73
|
+
"ServiceOptions",
|
74
|
+
"SourceCodeInfo",
|
75
|
+
"SourceCodeInfoLocation",
|
76
|
+
"SourceContext",
|
77
|
+
"StringValue",
|
78
|
+
"Struct",
|
79
|
+
"Timestamp",
|
80
|
+
"Type",
|
81
|
+
"UInt32Value",
|
82
|
+
"UInt64Value",
|
83
|
+
"UninterpretedOption",
|
84
|
+
"UninterpretedOptionNamePart",
|
85
|
+
"Value",
|
86
|
+
)
|
87
|
+
|
88
|
+
import datetime
|
89
|
+
import warnings
|
90
|
+
from dataclasses import dataclass
|
91
|
+
from typing import (
|
92
|
+
Dict,
|
93
|
+
List,
|
94
|
+
Optional,
|
95
|
+
)
|
96
|
+
|
97
|
+
import betterproto2
|
98
|
+
|
99
|
+
from ...message_pool import default_message_pool
|
100
|
+
|
101
|
+
betterproto2.check_compiler_version("0.2.0")
|
102
|
+
|
103
|
+
|
104
|
+
class Edition(betterproto2.Enum):
|
105
|
+
"""
|
106
|
+
The full set of known editions.
|
107
|
+
"""
|
108
|
+
|
109
|
+
UNKNOWN = 0
|
110
|
+
"""
|
111
|
+
A placeholder for an unknown edition value.
|
112
|
+
"""
|
113
|
+
|
114
|
+
PROTO2 = 998
|
115
|
+
"""
|
116
|
+
Legacy syntax "editions". These pre-date editions, but behave much like
|
117
|
+
distinct editions. These can't be used to specify the edition of proto
|
118
|
+
files, but feature definitions must supply proto2/proto3 defaults for
|
119
|
+
backwards compatibility.
|
120
|
+
"""
|
121
|
+
|
122
|
+
PROTO3 = 999
|
123
|
+
|
124
|
+
_2023 = 1000
|
125
|
+
"""
|
126
|
+
Editions that have been released. The specific values are arbitrary and
|
127
|
+
should not be depended on, but they will always be time-ordered for easy
|
128
|
+
comparison.
|
129
|
+
"""
|
130
|
+
|
131
|
+
_1_TEST_ONLY = 1
|
132
|
+
"""
|
133
|
+
Placeholder editions for testing feature resolution. These should not be
|
134
|
+
used or relyed on outside of tests.
|
135
|
+
"""
|
136
|
+
|
137
|
+
_2_TEST_ONLY = 2
|
138
|
+
|
139
|
+
_99997_TEST_ONLY = 99997
|
140
|
+
|
141
|
+
_99998_TEST_ONLY = 99998
|
142
|
+
|
143
|
+
_99999_TEST_ONLY = 99999
|
144
|
+
|
145
|
+
|
146
|
+
class ExtensionRangeOptionsVerificationState(betterproto2.Enum):
|
147
|
+
"""
|
148
|
+
The verification state of the extension range.
|
149
|
+
"""
|
150
|
+
|
151
|
+
DECLARATION = 0
|
152
|
+
"""
|
153
|
+
All the extensions of the range must be declared.
|
154
|
+
"""
|
155
|
+
|
156
|
+
UNVERIFIED = 1
|
157
|
+
|
158
|
+
|
159
|
+
class FeatureSetEnumType(betterproto2.Enum):
|
160
|
+
ENUM_TYPE_UNKNOWN = 0
|
161
|
+
|
162
|
+
OPEN = 1
|
163
|
+
|
164
|
+
CLOSED = 2
|
165
|
+
|
166
|
+
|
167
|
+
class FeatureSetFieldPresence(betterproto2.Enum):
|
168
|
+
FIELD_PRESENCE_UNKNOWN = 0
|
169
|
+
|
170
|
+
EXPLICIT = 1
|
171
|
+
|
172
|
+
IMPLICIT = 2
|
173
|
+
|
174
|
+
LEGACY_REQUIRED = 3
|
175
|
+
|
176
|
+
|
177
|
+
class FeatureSetJsonFormat(betterproto2.Enum):
|
178
|
+
JSON_FORMAT_UNKNOWN = 0
|
179
|
+
|
180
|
+
ALLOW = 1
|
181
|
+
|
182
|
+
LEGACY_BEST_EFFORT = 2
|
183
|
+
|
184
|
+
|
185
|
+
class FeatureSetMessageEncoding(betterproto2.Enum):
|
186
|
+
MESSAGE_ENCODING_UNKNOWN = 0
|
187
|
+
|
188
|
+
LENGTH_PREFIXED = 1
|
189
|
+
|
190
|
+
DELIMITED = 2
|
191
|
+
|
192
|
+
|
193
|
+
class FeatureSetRepeatedFieldEncoding(betterproto2.Enum):
|
194
|
+
REPEATED_FIELD_ENCODING_UNKNOWN = 0
|
195
|
+
|
196
|
+
PACKED = 1
|
197
|
+
|
198
|
+
EXPANDED = 2
|
199
|
+
|
200
|
+
|
201
|
+
class FeatureSetUtf8Validation(betterproto2.Enum):
|
202
|
+
UTF8_VALIDATION_UNKNOWN = 0
|
203
|
+
|
204
|
+
NONE = 1
|
205
|
+
|
206
|
+
VERIFY = 2
|
207
|
+
|
208
|
+
|
209
|
+
class FieldCardinality(betterproto2.Enum):
|
210
|
+
"""
|
211
|
+
Whether a field is optional, required, or repeated.
|
212
|
+
"""
|
213
|
+
|
214
|
+
CARDINALITY_UNKNOWN = 0
|
215
|
+
"""
|
216
|
+
For fields with unknown cardinality.
|
217
|
+
"""
|
218
|
+
|
219
|
+
CARDINALITY_OPTIONAL = 1
|
220
|
+
"""
|
221
|
+
For optional fields.
|
222
|
+
"""
|
223
|
+
|
224
|
+
CARDINALITY_REQUIRED = 2
|
225
|
+
"""
|
226
|
+
For required fields. Proto2 syntax only.
|
227
|
+
"""
|
228
|
+
|
229
|
+
CARDINALITY_REPEATED = 3
|
230
|
+
"""
|
231
|
+
For repeated fields.
|
232
|
+
"""
|
233
|
+
|
234
|
+
|
235
|
+
class FieldKind(betterproto2.Enum):
|
236
|
+
"""
|
237
|
+
Basic field types.
|
238
|
+
"""
|
239
|
+
|
240
|
+
TYPE_UNKNOWN = 0
|
241
|
+
"""
|
242
|
+
Field type unknown.
|
243
|
+
"""
|
244
|
+
|
245
|
+
TYPE_DOUBLE = 1
|
246
|
+
"""
|
247
|
+
Field type double.
|
248
|
+
"""
|
249
|
+
|
250
|
+
TYPE_FLOAT = 2
|
251
|
+
"""
|
252
|
+
Field type float.
|
253
|
+
"""
|
254
|
+
|
255
|
+
TYPE_INT64 = 3
|
256
|
+
"""
|
257
|
+
Field type int64.
|
258
|
+
"""
|
259
|
+
|
260
|
+
TYPE_UINT64 = 4
|
261
|
+
"""
|
262
|
+
Field type uint64.
|
263
|
+
"""
|
264
|
+
|
265
|
+
TYPE_INT32 = 5
|
266
|
+
"""
|
267
|
+
Field type int32.
|
268
|
+
"""
|
269
|
+
|
270
|
+
TYPE_FIXED64 = 6
|
271
|
+
"""
|
272
|
+
Field type fixed64.
|
273
|
+
"""
|
274
|
+
|
275
|
+
TYPE_FIXED32 = 7
|
276
|
+
"""
|
277
|
+
Field type fixed32.
|
278
|
+
"""
|
279
|
+
|
280
|
+
TYPE_BOOL = 8
|
281
|
+
"""
|
282
|
+
Field type bool.
|
283
|
+
"""
|
284
|
+
|
285
|
+
TYPE_STRING = 9
|
286
|
+
"""
|
287
|
+
Field type string.
|
288
|
+
"""
|
289
|
+
|
290
|
+
TYPE_GROUP = 10
|
291
|
+
"""
|
292
|
+
Field type group. Proto2 syntax only, and deprecated.
|
293
|
+
"""
|
294
|
+
|
295
|
+
TYPE_MESSAGE = 11
|
296
|
+
"""
|
297
|
+
Field type message.
|
298
|
+
"""
|
299
|
+
|
300
|
+
TYPE_BYTES = 12
|
301
|
+
"""
|
302
|
+
Field type bytes.
|
303
|
+
"""
|
304
|
+
|
305
|
+
TYPE_UINT32 = 13
|
306
|
+
"""
|
307
|
+
Field type uint32.
|
308
|
+
"""
|
309
|
+
|
310
|
+
TYPE_ENUM = 14
|
311
|
+
"""
|
312
|
+
Field type enum.
|
313
|
+
"""
|
314
|
+
|
315
|
+
TYPE_SFIXED32 = 15
|
316
|
+
"""
|
317
|
+
Field type sfixed32.
|
318
|
+
"""
|
319
|
+
|
320
|
+
TYPE_SFIXED64 = 16
|
321
|
+
"""
|
322
|
+
Field type sfixed64.
|
323
|
+
"""
|
324
|
+
|
325
|
+
TYPE_SINT32 = 17
|
326
|
+
"""
|
327
|
+
Field type sint32.
|
328
|
+
"""
|
329
|
+
|
330
|
+
TYPE_SINT64 = 18
|
331
|
+
"""
|
332
|
+
Field type sint64.
|
333
|
+
"""
|
334
|
+
|
335
|
+
|
336
|
+
class FieldDescriptorProtoLabel(betterproto2.Enum):
|
337
|
+
LABEL_OPTIONAL = 1
|
338
|
+
"""
|
339
|
+
0 is reserved for errors
|
340
|
+
"""
|
341
|
+
|
342
|
+
LABEL_REPEATED = 3
|
343
|
+
|
344
|
+
LABEL_REQUIRED = 2
|
345
|
+
"""
|
346
|
+
The required label is only allowed in google.protobuf. In proto3 and Editions
|
347
|
+
it's explicitly prohibited. In Editions, the `field_presence` feature
|
348
|
+
can be used to get this behavior.
|
349
|
+
"""
|
350
|
+
|
351
|
+
|
352
|
+
class FieldDescriptorProtoType(betterproto2.Enum):
|
353
|
+
TYPE_DOUBLE = 1
|
354
|
+
"""
|
355
|
+
0 is reserved for errors.
|
356
|
+
Order is weird for historical reasons.
|
357
|
+
"""
|
358
|
+
|
359
|
+
TYPE_FLOAT = 2
|
360
|
+
|
361
|
+
TYPE_INT64 = 3
|
362
|
+
"""
|
363
|
+
Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
|
364
|
+
negative values are likely.
|
365
|
+
"""
|
366
|
+
|
367
|
+
TYPE_UINT64 = 4
|
368
|
+
|
369
|
+
TYPE_INT32 = 5
|
370
|
+
"""
|
371
|
+
Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
|
372
|
+
negative values are likely.
|
373
|
+
"""
|
374
|
+
|
375
|
+
TYPE_FIXED64 = 6
|
376
|
+
|
377
|
+
TYPE_FIXED32 = 7
|
378
|
+
|
379
|
+
TYPE_BOOL = 8
|
380
|
+
|
381
|
+
TYPE_STRING = 9
|
382
|
+
|
383
|
+
TYPE_GROUP = 10
|
384
|
+
"""
|
385
|
+
Tag-delimited aggregate.
|
386
|
+
Group type is deprecated and not supported after google.protobuf. However, Proto3
|
387
|
+
implementations should still be able to parse the group wire format and
|
388
|
+
treat group fields as unknown fields. In Editions, the group wire format
|
389
|
+
can be enabled via the `message_encoding` feature.
|
390
|
+
"""
|
391
|
+
|
392
|
+
TYPE_MESSAGE = 11
|
393
|
+
"""
|
394
|
+
Length-delimited aggregate.
|
395
|
+
"""
|
396
|
+
|
397
|
+
TYPE_BYTES = 12
|
398
|
+
"""
|
399
|
+
New in version 2.
|
400
|
+
"""
|
401
|
+
|
402
|
+
TYPE_UINT32 = 13
|
403
|
+
|
404
|
+
TYPE_ENUM = 14
|
405
|
+
|
406
|
+
TYPE_SFIXED32 = 15
|
407
|
+
|
408
|
+
TYPE_SFIXED64 = 16
|
409
|
+
|
410
|
+
TYPE_SINT32 = 17
|
411
|
+
"""
|
412
|
+
Uses ZigZag encoding.
|
413
|
+
"""
|
414
|
+
|
415
|
+
TYPE_SINT64 = 18
|
416
|
+
"""
|
417
|
+
Uses ZigZag encoding.
|
418
|
+
"""
|
419
|
+
|
420
|
+
|
421
|
+
class FieldOptionsCType(betterproto2.Enum):
|
422
|
+
STRING = 0
|
423
|
+
"""
|
424
|
+
Default mode.
|
425
|
+
"""
|
426
|
+
|
427
|
+
CORD = 1
|
428
|
+
"""
|
429
|
+
The option [ctype=CORD] may be applied to a non-repeated field of type
|
430
|
+
"bytes". It indicates that in C++, the data should be stored in a Cord
|
431
|
+
instead of a string. For very large strings, this may reduce memory
|
432
|
+
fragmentation. It may also allow better performance when parsing from a
|
433
|
+
Cord, or when parsing with aliasing enabled, as the parsed Cord may then
|
434
|
+
alias the original buffer.
|
435
|
+
"""
|
436
|
+
|
437
|
+
STRING_PIECE = 2
|
438
|
+
|
439
|
+
|
440
|
+
class FieldOptionsJsType(betterproto2.Enum):
|
441
|
+
JS_NORMAL = 0
|
442
|
+
"""
|
443
|
+
Use the default type.
|
444
|
+
"""
|
445
|
+
|
446
|
+
JS_STRING = 1
|
447
|
+
"""
|
448
|
+
Use JavaScript strings.
|
449
|
+
"""
|
450
|
+
|
451
|
+
JS_NUMBER = 2
|
452
|
+
"""
|
453
|
+
Use JavaScript numbers.
|
454
|
+
"""
|
455
|
+
|
456
|
+
|
457
|
+
class FieldOptionsOptionRetention(betterproto2.Enum):
|
458
|
+
"""
|
459
|
+
If set to RETENTION_SOURCE, the option will be omitted from the binary.
|
460
|
+
Note: as of January 2023, support for this is in progress and does not yet
|
461
|
+
have an effect (b/264593489).
|
462
|
+
"""
|
463
|
+
|
464
|
+
RETENTION_UNKNOWN = 0
|
465
|
+
|
466
|
+
RETENTION_RUNTIME = 1
|
467
|
+
|
468
|
+
RETENTION_SOURCE = 2
|
469
|
+
|
470
|
+
|
471
|
+
class FieldOptionsOptionTargetType(betterproto2.Enum):
|
472
|
+
"""
|
473
|
+
This indicates the types of entities that the field may apply to when used
|
474
|
+
as an option. If it is unset, then the field may be freely used as an
|
475
|
+
option on any kind of entity. Note: as of January 2023, support for this is
|
476
|
+
in progress and does not yet have an effect (b/264593489).
|
477
|
+
"""
|
478
|
+
|
479
|
+
TARGET_TYPE_UNKNOWN = 0
|
480
|
+
|
481
|
+
TARGET_TYPE_FILE = 1
|
482
|
+
|
483
|
+
TARGET_TYPE_EXTENSION_RANGE = 2
|
484
|
+
|
485
|
+
TARGET_TYPE_MESSAGE = 3
|
486
|
+
|
487
|
+
TARGET_TYPE_FIELD = 4
|
488
|
+
|
489
|
+
TARGET_TYPE_ONEOF = 5
|
490
|
+
|
491
|
+
TARGET_TYPE_ENUM = 6
|
492
|
+
|
493
|
+
TARGET_TYPE_ENUM_ENTRY = 7
|
494
|
+
|
495
|
+
TARGET_TYPE_SERVICE = 8
|
496
|
+
|
497
|
+
TARGET_TYPE_METHOD = 9
|
498
|
+
|
499
|
+
|
500
|
+
class FileOptionsOptimizeMode(betterproto2.Enum):
|
501
|
+
"""
|
502
|
+
Generated classes can be optimized for speed or code size.
|
503
|
+
"""
|
504
|
+
|
505
|
+
SPEED = 1
|
506
|
+
"""
|
507
|
+
Generate complete code for parsing, serialization,
|
508
|
+
"""
|
509
|
+
|
510
|
+
CODE_SIZE = 2
|
511
|
+
"""
|
512
|
+
etc.
|
513
|
+
|
514
|
+
Use ReflectionOps to implement these methods.
|
515
|
+
"""
|
516
|
+
|
517
|
+
LITE_RUNTIME = 3
|
518
|
+
"""
|
519
|
+
Generate code using MessageLite and the lite runtime.
|
520
|
+
"""
|
521
|
+
|
522
|
+
|
523
|
+
class GeneratedCodeInfoAnnotationSemantic(betterproto2.Enum):
|
524
|
+
"""
|
525
|
+
Represents the identified object's effect on the element in the original
|
526
|
+
.proto file.
|
527
|
+
"""
|
528
|
+
|
529
|
+
NONE = 0
|
530
|
+
"""
|
531
|
+
There is no effect or the effect is indescribable.
|
532
|
+
"""
|
533
|
+
|
534
|
+
SET = 1
|
535
|
+
"""
|
536
|
+
The element is set or otherwise mutated.
|
537
|
+
"""
|
538
|
+
|
539
|
+
ALIAS = 2
|
540
|
+
"""
|
541
|
+
An alias to the element is returned.
|
542
|
+
"""
|
543
|
+
|
544
|
+
|
545
|
+
class MethodOptionsIdempotencyLevel(betterproto2.Enum):
|
546
|
+
"""
|
547
|
+
Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
|
548
|
+
or neither? HTTP based RPC implementation may choose GET verb for safe
|
549
|
+
methods, and PUT verb for idempotent methods instead of the default POST.
|
550
|
+
"""
|
551
|
+
|
552
|
+
IDEMPOTENCY_UNKNOWN = 0
|
553
|
+
|
554
|
+
NO_SIDE_EFFECTS = 1
|
555
|
+
"""
|
556
|
+
implies idempotent
|
557
|
+
"""
|
558
|
+
|
559
|
+
IDEMPOTENT = 2
|
560
|
+
"""
|
561
|
+
idempotent, but may have side effects
|
562
|
+
"""
|
563
|
+
|
564
|
+
|
565
|
+
class NullValue(betterproto2.Enum):
|
566
|
+
"""
|
567
|
+
`NullValue` is a singleton enumeration to represent the null value for the
|
568
|
+
`Value` type union.
|
569
|
+
|
570
|
+
The JSON representation for `NullValue` is JSON `null`.
|
571
|
+
"""
|
572
|
+
|
573
|
+
_ = 0
|
574
|
+
"""
|
575
|
+
Null value.
|
576
|
+
"""
|
577
|
+
|
578
|
+
|
579
|
+
class Syntax(betterproto2.Enum):
|
580
|
+
"""
|
581
|
+
The syntax in which a protocol buffer element is defined.
|
582
|
+
"""
|
583
|
+
|
584
|
+
PROTO2 = 0
|
585
|
+
"""
|
586
|
+
Syntax `proto2`.
|
587
|
+
"""
|
588
|
+
|
589
|
+
PROTO3 = 1
|
590
|
+
"""
|
591
|
+
Syntax `proto3`.
|
592
|
+
"""
|
593
|
+
|
594
|
+
EDITIONS = 2
|
595
|
+
"""
|
596
|
+
Syntax `editions`.
|
597
|
+
"""
|
598
|
+
|
599
|
+
|
600
|
+
@dataclass(eq=False, repr=False)
|
601
|
+
class Any(betterproto2.Message):
|
602
|
+
"""
|
603
|
+
`Any` contains an arbitrary serialized protocol buffer message along with a
|
604
|
+
URL that describes the type of the serialized message.
|
605
|
+
|
606
|
+
Protobuf library provides support to pack/unpack Any values in the form
|
607
|
+
of utility functions or additional generated methods of the Any type.
|
608
|
+
|
609
|
+
Example 1: Pack and unpack a message in C++.
|
610
|
+
|
611
|
+
Foo foo = ...;
|
612
|
+
Any any;
|
613
|
+
any.PackFrom(foo);
|
614
|
+
...
|
615
|
+
if (any.UnpackTo(&foo)) {
|
616
|
+
...
|
617
|
+
}
|
618
|
+
|
619
|
+
Example 2: Pack and unpack a message in Java.
|
620
|
+
|
621
|
+
Foo foo = ...;
|
622
|
+
Any any = Any.pack(foo);
|
623
|
+
...
|
624
|
+
if (any.is(Foo.class)) {
|
625
|
+
foo = any.unpack(Foo.class);
|
626
|
+
}
|
627
|
+
// or ...
|
628
|
+
if (any.isSameTypeAs(Foo.getDefaultInstance())) {
|
629
|
+
foo = any.unpack(Foo.getDefaultInstance());
|
630
|
+
}
|
631
|
+
|
632
|
+
Example 3: Pack and unpack a message in Python.
|
633
|
+
|
634
|
+
foo = Foo(...)
|
635
|
+
any = Any()
|
636
|
+
any.Pack(foo)
|
637
|
+
...
|
638
|
+
if any.Is(Foo.DESCRIPTOR):
|
639
|
+
any.Unpack(foo)
|
640
|
+
...
|
641
|
+
|
642
|
+
Example 4: Pack and unpack a message in Go
|
643
|
+
|
644
|
+
foo := &pb.Foo{...}
|
645
|
+
any, err := anypb.New(foo)
|
646
|
+
if err != nil {
|
647
|
+
...
|
648
|
+
}
|
649
|
+
...
|
650
|
+
foo := &pb.Foo{}
|
651
|
+
if err := any.UnmarshalTo(foo); err != nil {
|
652
|
+
...
|
653
|
+
}
|
654
|
+
|
655
|
+
The pack methods provided by protobuf library will by default use
|
656
|
+
'type.googleapis.com/full.type.name' as the type URL and the unpack
|
657
|
+
methods only use the fully qualified type name after the last '/'
|
658
|
+
in the type URL, for example "foo.bar.com/x/y.z" will yield type
|
659
|
+
name "y.z".
|
660
|
+
|
661
|
+
JSON
|
662
|
+
====
|
663
|
+
The JSON representation of an `Any` value uses the regular
|
664
|
+
representation of the deserialized, embedded message, with an
|
665
|
+
additional field `@type` which contains the type URL. Example:
|
666
|
+
|
667
|
+
package google.profile;
|
668
|
+
message Person {
|
669
|
+
string first_name = 1;
|
670
|
+
string last_name = 2;
|
671
|
+
}
|
672
|
+
|
673
|
+
{
|
674
|
+
"@type": "type.googleapis.com/google.profile.Person",
|
675
|
+
"firstName": <string>,
|
676
|
+
"lastName": <string>
|
677
|
+
}
|
678
|
+
|
679
|
+
If the embedded message type is well-known and has a custom JSON
|
680
|
+
representation, that representation will be embedded adding a field
|
681
|
+
`value` which holds the custom JSON in addition to the `@type`
|
682
|
+
field. Example (for message [google.protobuf.Duration][]):
|
683
|
+
|
684
|
+
{
|
685
|
+
"@type": "type.googleapis.com/google.protobuf.Duration",
|
686
|
+
"value": "1.212s"
|
687
|
+
}
|
688
|
+
"""
|
689
|
+
|
690
|
+
type_url: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
691
|
+
"""
|
692
|
+
A URL/resource name that uniquely identifies the type of the serialized
|
693
|
+
protocol buffer message. This string must contain at least
|
694
|
+
one "/" character. The last segment of the URL's path must represent
|
695
|
+
the fully qualified name of the type (as in
|
696
|
+
`path/google.protobuf.Duration`). The name should be in a canonical form
|
697
|
+
(e.g., leading "." is not accepted).
|
698
|
+
|
699
|
+
In practice, teams usually precompile into the binary all types that they
|
700
|
+
expect it to use in the context of Any. However, for URLs which use the
|
701
|
+
scheme `http`, `https`, or no scheme, one can optionally set up a type
|
702
|
+
server that maps type URLs to message definitions as follows:
|
703
|
+
|
704
|
+
* If no scheme is provided, `https` is assumed.
|
705
|
+
* An HTTP GET on the URL must yield a [google.protobuf.Type][]
|
706
|
+
value in binary format, or produce an error.
|
707
|
+
* Applications are allowed to cache lookup results based on the
|
708
|
+
URL, or have them precompiled into a binary to avoid any
|
709
|
+
lookup. Therefore, binary compatibility needs to be preserved
|
710
|
+
on changes to types. (Use versioned type names to manage
|
711
|
+
breaking changes.)
|
712
|
+
|
713
|
+
Note: this functionality is not currently available in the official
|
714
|
+
protobuf release, and it is not used for type URLs beginning with
|
715
|
+
type.googleapis.com. As of May 2023, there are no widely used type server
|
716
|
+
implementations and no plans to implement one.
|
717
|
+
|
718
|
+
Schemes other than `http`, `https` (or the empty scheme) might be
|
719
|
+
used with implementation specific semantics.
|
720
|
+
"""
|
721
|
+
|
722
|
+
value: "bytes" = betterproto2.field(2, betterproto2.TYPE_BYTES)
|
723
|
+
"""
|
724
|
+
Must be a valid serialized protocol buffer of the above specified type.
|
725
|
+
"""
|
726
|
+
|
727
|
+
def pack(self, message: betterproto2.Message, message_pool: "betterproto2.MessagePool | None" = None) -> None:
|
728
|
+
"""
|
729
|
+
Pack the given message in the `Any` object.
|
730
|
+
|
731
|
+
The message type must be registered in the message pool, which is done automatically when the module defining
|
732
|
+
the message type is imported.
|
733
|
+
"""
|
734
|
+
message_pool = message_pool or default_message_pool
|
735
|
+
|
736
|
+
self.type_url = message_pool.type_to_url[type(message)]
|
737
|
+
self.value = bytes(message)
|
738
|
+
|
739
|
+
def unpack(self, message_pool: "betterproto2.MessagePool | None" = None) -> betterproto2.Message:
|
740
|
+
"""
|
741
|
+
Return the message packed inside the `Any` object.
|
742
|
+
|
743
|
+
The target message type must be registered in the message pool, which is done automatically when the module
|
744
|
+
defining the message type is imported.
|
745
|
+
"""
|
746
|
+
message_pool = message_pool or default_message_pool
|
747
|
+
|
748
|
+
message_type = message_pool.url_to_type[self.type_url]
|
749
|
+
|
750
|
+
return message_type().parse(self.value)
|
751
|
+
|
752
|
+
def to_dict(self) -> dict: # pyright: ignore [reportIncompatibleMethodOverride]
|
753
|
+
# TOOO improve when dict is updated
|
754
|
+
return {"@type": self.type_url, "value": self.unpack().to_dict()}
|
755
|
+
|
756
|
+
|
757
|
+
default_message_pool.register_message("google.protobuf", "Any", Any)
|
758
|
+
|
759
|
+
|
760
|
+
@dataclass(eq=False, repr=False)
|
761
|
+
class Api(betterproto2.Message):
|
762
|
+
"""
|
763
|
+
Api is a light-weight descriptor for an API Interface.
|
764
|
+
|
765
|
+
Interfaces are also described as "protocol buffer services" in some contexts,
|
766
|
+
such as by the "service" keyword in a .proto file, but they are different
|
767
|
+
from API Services, which represent a concrete implementation of an interface
|
768
|
+
as opposed to simply a description of methods and bindings. They are also
|
769
|
+
sometimes simply referred to as "APIs" in other contexts, such as the name of
|
770
|
+
this message itself. See https://cloud.google.com/apis/design/glossary for
|
771
|
+
detailed terminology.
|
772
|
+
"""
|
773
|
+
|
774
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
775
|
+
"""
|
776
|
+
The fully qualified name of this interface, including package name
|
777
|
+
followed by the interface's simple name.
|
778
|
+
"""
|
779
|
+
|
780
|
+
methods: "List[Method]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
781
|
+
"""
|
782
|
+
The methods of this interface, in unspecified order.
|
783
|
+
"""
|
784
|
+
|
785
|
+
options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
|
786
|
+
"""
|
787
|
+
Any metadata attached to the interface.
|
788
|
+
"""
|
789
|
+
|
790
|
+
version: "str" = betterproto2.field(4, betterproto2.TYPE_STRING)
|
791
|
+
"""
|
792
|
+
A version string for this interface. If specified, must have the form
|
793
|
+
`major-version.minor-version`, as in `1.10`. If the minor version is
|
794
|
+
omitted, it defaults to zero. If the entire version field is empty, the
|
795
|
+
major version is derived from the package name, as outlined below. If the
|
796
|
+
field is not empty, the version in the package name will be verified to be
|
797
|
+
consistent with what is provided here.
|
798
|
+
|
799
|
+
The versioning schema uses [semantic
|
800
|
+
versioning](http://semver.org) where the major version number
|
801
|
+
indicates a breaking change and the minor version an additive,
|
802
|
+
non-breaking change. Both version numbers are signals to users
|
803
|
+
what to expect from different versions, and should be carefully
|
804
|
+
chosen based on the product plan.
|
805
|
+
|
806
|
+
The major version is also reflected in the package name of the
|
807
|
+
interface, which must end in `v<major-version>`, as in
|
808
|
+
`google.feature.v1`. For major versions 0 and 1, the suffix can
|
809
|
+
be omitted. Zero major versions must only be used for
|
810
|
+
experimental, non-GA interfaces.
|
811
|
+
"""
|
812
|
+
|
813
|
+
source_context: "Optional[SourceContext]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
|
814
|
+
"""
|
815
|
+
Source context for the protocol buffer service represented by this
|
816
|
+
message.
|
817
|
+
"""
|
818
|
+
|
819
|
+
mixins: "List[Mixin]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
|
820
|
+
"""
|
821
|
+
Included interfaces. See [Mixin][].
|
822
|
+
"""
|
823
|
+
|
824
|
+
syntax: "Syntax" = betterproto2.field(7, betterproto2.TYPE_ENUM, default_factory=lambda: Syntax.try_value(0))
|
825
|
+
"""
|
826
|
+
The source syntax of the service.
|
827
|
+
"""
|
828
|
+
|
829
|
+
|
830
|
+
default_message_pool.register_message("google.protobuf", "Api", Api)
|
831
|
+
|
832
|
+
|
833
|
+
@dataclass(eq=False, repr=False)
|
834
|
+
class BoolValue(betterproto2.Message):
|
835
|
+
"""
|
836
|
+
Wrapper message for `bool`.
|
837
|
+
|
838
|
+
The JSON representation for `BoolValue` is JSON `true` and `false`.
|
839
|
+
"""
|
840
|
+
|
841
|
+
value: "bool" = betterproto2.field(1, betterproto2.TYPE_BOOL)
|
842
|
+
"""
|
843
|
+
The bool value.
|
844
|
+
"""
|
845
|
+
|
846
|
+
|
847
|
+
default_message_pool.register_message("google.protobuf", "BoolValue", BoolValue)
|
848
|
+
|
849
|
+
|
850
|
+
@dataclass(eq=False, repr=False)
|
851
|
+
class BytesValue(betterproto2.Message):
|
852
|
+
"""
|
853
|
+
Wrapper message for `bytes`.
|
854
|
+
|
855
|
+
The JSON representation for `BytesValue` is JSON string.
|
856
|
+
"""
|
857
|
+
|
858
|
+
value: "bytes" = betterproto2.field(1, betterproto2.TYPE_BYTES)
|
859
|
+
"""
|
860
|
+
The bytes value.
|
861
|
+
"""
|
862
|
+
|
863
|
+
|
864
|
+
default_message_pool.register_message("google.protobuf", "BytesValue", BytesValue)
|
865
|
+
|
866
|
+
|
867
|
+
@dataclass(eq=False, repr=False)
|
868
|
+
class DescriptorProto(betterproto2.Message):
|
869
|
+
"""
|
870
|
+
Describes a message type.
|
871
|
+
"""
|
872
|
+
|
873
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
874
|
+
|
875
|
+
field: "List[FieldDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
876
|
+
|
877
|
+
extension: "List[FieldDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
|
878
|
+
|
879
|
+
nested_type: "List[DescriptorProto]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
|
880
|
+
|
881
|
+
enum_type: "List[EnumDescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
|
882
|
+
|
883
|
+
extension_range: "List[DescriptorProtoExtensionRange]" = betterproto2.field(
|
884
|
+
5, betterproto2.TYPE_MESSAGE, repeated=True
|
885
|
+
)
|
886
|
+
|
887
|
+
oneof_decl: "List[OneofDescriptorProto]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, repeated=True)
|
888
|
+
|
889
|
+
options: "Optional[MessageOptions]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, optional=True)
|
890
|
+
|
891
|
+
reserved_range: "List[DescriptorProtoReservedRange]" = betterproto2.field(
|
892
|
+
9, betterproto2.TYPE_MESSAGE, repeated=True
|
893
|
+
)
|
894
|
+
|
895
|
+
reserved_name: "List[str]" = betterproto2.field(10, betterproto2.TYPE_STRING, repeated=True)
|
896
|
+
"""
|
897
|
+
Reserved field names, which may not be used by fields in the same message.
|
898
|
+
A given name may only be reserved once.
|
899
|
+
"""
|
900
|
+
|
901
|
+
|
902
|
+
default_message_pool.register_message("google.protobuf", "DescriptorProto", DescriptorProto)
|
903
|
+
|
904
|
+
|
905
|
+
@dataclass(eq=False, repr=False)
|
906
|
+
class DescriptorProtoExtensionRange(betterproto2.Message):
|
907
|
+
start: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
|
908
|
+
"""
|
909
|
+
Inclusive.
|
910
|
+
"""
|
911
|
+
|
912
|
+
end: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
913
|
+
"""
|
914
|
+
Exclusive.
|
915
|
+
"""
|
916
|
+
|
917
|
+
options: "Optional[ExtensionRangeOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
|
918
|
+
|
919
|
+
|
920
|
+
default_message_pool.register_message(
|
921
|
+
"google.protobuf", "DescriptorProto.ExtensionRange", DescriptorProtoExtensionRange
|
922
|
+
)
|
923
|
+
|
924
|
+
|
925
|
+
@dataclass(eq=False, repr=False)
|
926
|
+
class DescriptorProtoReservedRange(betterproto2.Message):
|
927
|
+
"""
|
928
|
+
Range of reserved tag numbers. Reserved tag numbers may not be used by
|
929
|
+
fields or extension ranges in the same message. Reserved ranges may
|
930
|
+
not overlap.
|
931
|
+
"""
|
932
|
+
|
933
|
+
start: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
|
934
|
+
"""
|
935
|
+
Inclusive.
|
936
|
+
"""
|
937
|
+
|
938
|
+
end: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
939
|
+
"""
|
940
|
+
Exclusive.
|
941
|
+
"""
|
942
|
+
|
943
|
+
|
944
|
+
default_message_pool.register_message("google.protobuf", "DescriptorProto.ReservedRange", DescriptorProtoReservedRange)
|
945
|
+
|
946
|
+
|
947
|
+
@dataclass(eq=False, repr=False)
|
948
|
+
class DoubleValue(betterproto2.Message):
|
949
|
+
"""
|
950
|
+
Wrapper message for `double`.
|
951
|
+
|
952
|
+
The JSON representation for `DoubleValue` is JSON number.
|
953
|
+
"""
|
954
|
+
|
955
|
+
value: "float" = betterproto2.field(1, betterproto2.TYPE_DOUBLE)
|
956
|
+
"""
|
957
|
+
The double value.
|
958
|
+
"""
|
959
|
+
|
960
|
+
|
961
|
+
default_message_pool.register_message("google.protobuf", "DoubleValue", DoubleValue)
|
962
|
+
|
963
|
+
|
964
|
+
@dataclass(eq=False, repr=False)
|
965
|
+
class Duration(betterproto2.Message):
|
966
|
+
"""
|
967
|
+
A Duration represents a signed, fixed-length span of time represented
|
968
|
+
as a count of seconds and fractions of seconds at nanosecond
|
969
|
+
resolution. It is independent of any calendar and concepts like "day"
|
970
|
+
or "month". It is related to Timestamp in that the difference between
|
971
|
+
two Timestamp values is a Duration and it can be added or subtracted
|
972
|
+
from a Timestamp. Range is approximately +-10,000 years.
|
973
|
+
|
974
|
+
# Examples
|
975
|
+
|
976
|
+
Example 1: Compute Duration from two Timestamps in pseudo code.
|
977
|
+
|
978
|
+
Timestamp start = ...;
|
979
|
+
Timestamp end = ...;
|
980
|
+
Duration duration = ...;
|
981
|
+
|
982
|
+
duration.seconds = end.seconds - start.seconds;
|
983
|
+
duration.nanos = end.nanos - start.nanos;
|
984
|
+
|
985
|
+
if (duration.seconds < 0 && duration.nanos > 0) {
|
986
|
+
duration.seconds += 1;
|
987
|
+
duration.nanos -= 1000000000;
|
988
|
+
} else if (duration.seconds > 0 && duration.nanos < 0) {
|
989
|
+
duration.seconds -= 1;
|
990
|
+
duration.nanos += 1000000000;
|
991
|
+
}
|
992
|
+
|
993
|
+
Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
|
994
|
+
|
995
|
+
Timestamp start = ...;
|
996
|
+
Duration duration = ...;
|
997
|
+
Timestamp end = ...;
|
998
|
+
|
999
|
+
end.seconds = start.seconds + duration.seconds;
|
1000
|
+
end.nanos = start.nanos + duration.nanos;
|
1001
|
+
|
1002
|
+
if (end.nanos < 0) {
|
1003
|
+
end.seconds -= 1;
|
1004
|
+
end.nanos += 1000000000;
|
1005
|
+
} else if (end.nanos >= 1000000000) {
|
1006
|
+
end.seconds += 1;
|
1007
|
+
end.nanos -= 1000000000;
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
Example 3: Compute Duration from datetime.timedelta in Python.
|
1011
|
+
|
1012
|
+
td = datetime.timedelta(days=3, minutes=10)
|
1013
|
+
duration = Duration()
|
1014
|
+
duration.FromTimedelta(td)
|
1015
|
+
|
1016
|
+
# JSON Mapping
|
1017
|
+
|
1018
|
+
In JSON format, the Duration type is encoded as a string rather than an
|
1019
|
+
object, where the string ends in the suffix "s" (indicating seconds) and
|
1020
|
+
is preceded by the number of seconds, with nanoseconds expressed as
|
1021
|
+
fractional seconds. For example, 3 seconds with 0 nanoseconds should be
|
1022
|
+
encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
|
1023
|
+
be expressed in JSON format as "3.000000001s", and 3 seconds and 1
|
1024
|
+
microsecond should be expressed in JSON format as "3.000001s".
|
1025
|
+
"""
|
1026
|
+
|
1027
|
+
seconds: "int" = betterproto2.field(1, betterproto2.TYPE_INT64)
|
1028
|
+
"""
|
1029
|
+
Signed seconds of the span of time. Must be from -315,576,000,000
|
1030
|
+
to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
1031
|
+
60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
1032
|
+
"""
|
1033
|
+
|
1034
|
+
nanos: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
1035
|
+
"""
|
1036
|
+
Signed fractions of a second at nanosecond resolution of the span
|
1037
|
+
of time. Durations less than one second are represented with a 0
|
1038
|
+
`seconds` field and a positive or negative `nanos` field. For durations
|
1039
|
+
of one second or more, a non-zero value for the `nanos` field must be
|
1040
|
+
of the same sign as the `seconds` field. Must be from -999,999,999
|
1041
|
+
to +999,999,999 inclusive.
|
1042
|
+
"""
|
1043
|
+
|
1044
|
+
@classmethod
|
1045
|
+
def from_timedelta(
|
1046
|
+
cls, delta: datetime.timedelta, *, _1_microsecond: datetime.timedelta = datetime.timedelta(microseconds=1)
|
1047
|
+
) -> "Duration":
|
1048
|
+
total_ms = delta // _1_microsecond
|
1049
|
+
seconds = int(total_ms / 1e6)
|
1050
|
+
nanos = int((total_ms % 1e6) * 1e3)
|
1051
|
+
return cls(seconds, nanos)
|
1052
|
+
|
1053
|
+
def to_timedelta(self) -> datetime.timedelta:
|
1054
|
+
return datetime.timedelta(seconds=self.seconds, microseconds=self.nanos / 1e3)
|
1055
|
+
|
1056
|
+
@staticmethod
|
1057
|
+
def delta_to_json(delta: datetime.timedelta) -> str:
|
1058
|
+
parts = str(delta.total_seconds()).split(".")
|
1059
|
+
if len(parts) > 1:
|
1060
|
+
while len(parts[1]) not in (3, 6, 9):
|
1061
|
+
parts[1] = f"{parts[1]}0"
|
1062
|
+
return f"{'.'.join(parts)}s"
|
1063
|
+
|
1064
|
+
|
1065
|
+
default_message_pool.register_message("google.protobuf", "Duration", Duration)
|
1066
|
+
|
1067
|
+
|
1068
|
+
@dataclass(eq=False, repr=False)
|
1069
|
+
class Empty(betterproto2.Message):
|
1070
|
+
"""
|
1071
|
+
A generic empty message that you can re-use to avoid defining duplicated
|
1072
|
+
empty messages in your APIs. A typical example is to use it as the request
|
1073
|
+
or the response type of an API method. For instance:
|
1074
|
+
|
1075
|
+
service Foo {
|
1076
|
+
rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
|
1077
|
+
}
|
1078
|
+
"""
|
1079
|
+
|
1080
|
+
pass
|
1081
|
+
|
1082
|
+
|
1083
|
+
default_message_pool.register_message("google.protobuf", "Empty", Empty)
|
1084
|
+
|
1085
|
+
|
1086
|
+
@dataclass(eq=False, repr=False)
|
1087
|
+
class Enum(betterproto2.Message):
|
1088
|
+
"""
|
1089
|
+
Enum type definition.
|
1090
|
+
"""
|
1091
|
+
|
1092
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1093
|
+
"""
|
1094
|
+
Enum type name.
|
1095
|
+
"""
|
1096
|
+
|
1097
|
+
enumvalue: "List[EnumValue]" = betterproto2.field(
|
1098
|
+
2, betterproto2.TYPE_MESSAGE, wraps=betterproto2.TYPE_ENUM, repeated=True
|
1099
|
+
)
|
1100
|
+
"""
|
1101
|
+
Enum value definitions.
|
1102
|
+
"""
|
1103
|
+
|
1104
|
+
options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
|
1105
|
+
"""
|
1106
|
+
Protocol buffer options.
|
1107
|
+
"""
|
1108
|
+
|
1109
|
+
source_context: "Optional[SourceContext]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
|
1110
|
+
"""
|
1111
|
+
The source context.
|
1112
|
+
"""
|
1113
|
+
|
1114
|
+
syntax: "Syntax" = betterproto2.field(5, betterproto2.TYPE_ENUM, default_factory=lambda: Syntax.try_value(0))
|
1115
|
+
"""
|
1116
|
+
The source syntax.
|
1117
|
+
"""
|
1118
|
+
|
1119
|
+
edition: "str" = betterproto2.field(6, betterproto2.TYPE_STRING)
|
1120
|
+
"""
|
1121
|
+
The source edition string, only valid when syntax is SYNTAX_EDITIONS.
|
1122
|
+
"""
|
1123
|
+
|
1124
|
+
|
1125
|
+
default_message_pool.register_message("google.protobuf", "Enum", Enum)
|
1126
|
+
|
1127
|
+
|
1128
|
+
@dataclass(eq=False, repr=False)
|
1129
|
+
class EnumDescriptorProto(betterproto2.Message):
|
1130
|
+
"""
|
1131
|
+
Describes an enum type.
|
1132
|
+
"""
|
1133
|
+
|
1134
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1135
|
+
|
1136
|
+
value: "List[EnumValueDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
1137
|
+
|
1138
|
+
options: "Optional[EnumOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
|
1139
|
+
|
1140
|
+
reserved_range: "List[EnumDescriptorProtoEnumReservedRange]" = betterproto2.field(
|
1141
|
+
4, betterproto2.TYPE_MESSAGE, repeated=True
|
1142
|
+
)
|
1143
|
+
"""
|
1144
|
+
Range of reserved numeric values. Reserved numeric values may not be used
|
1145
|
+
by enum values in the same enum declaration. Reserved ranges may not
|
1146
|
+
overlap.
|
1147
|
+
"""
|
1148
|
+
|
1149
|
+
reserved_name: "List[str]" = betterproto2.field(5, betterproto2.TYPE_STRING, repeated=True)
|
1150
|
+
"""
|
1151
|
+
Reserved enum value names, which may not be reused. A given name may only
|
1152
|
+
be reserved once.
|
1153
|
+
"""
|
1154
|
+
|
1155
|
+
|
1156
|
+
default_message_pool.register_message("google.protobuf", "EnumDescriptorProto", EnumDescriptorProto)
|
1157
|
+
|
1158
|
+
|
1159
|
+
@dataclass(eq=False, repr=False)
|
1160
|
+
class EnumDescriptorProtoEnumReservedRange(betterproto2.Message):
|
1161
|
+
"""
|
1162
|
+
Range of reserved numeric values. Reserved values may not be used by
|
1163
|
+
entries in the same enum. Reserved ranges may not overlap.
|
1164
|
+
|
1165
|
+
Note that this is distinct from DescriptorProto.ReservedRange in that it
|
1166
|
+
is inclusive such that it can appropriately represent the entire int32
|
1167
|
+
domain.
|
1168
|
+
"""
|
1169
|
+
|
1170
|
+
start: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
|
1171
|
+
"""
|
1172
|
+
Inclusive.
|
1173
|
+
"""
|
1174
|
+
|
1175
|
+
end: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
1176
|
+
"""
|
1177
|
+
Inclusive.
|
1178
|
+
"""
|
1179
|
+
|
1180
|
+
|
1181
|
+
default_message_pool.register_message(
|
1182
|
+
"google.protobuf", "EnumDescriptorProto.EnumReservedRange", EnumDescriptorProtoEnumReservedRange
|
1183
|
+
)
|
1184
|
+
|
1185
|
+
|
1186
|
+
@dataclass(eq=False, repr=False)
|
1187
|
+
class EnumOptions(betterproto2.Message):
|
1188
|
+
allow_alias: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
|
1189
|
+
"""
|
1190
|
+
Set this option to true to allow mapping different tag names to the same
|
1191
|
+
value.
|
1192
|
+
"""
|
1193
|
+
|
1194
|
+
deprecated: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
|
1195
|
+
"""
|
1196
|
+
Is this enum deprecated?
|
1197
|
+
Depending on the target platform, this can emit Deprecated annotations
|
1198
|
+
for the enum, or it will be completely ignored; in the very least, this
|
1199
|
+
is a formalization for deprecating enums.
|
1200
|
+
"""
|
1201
|
+
|
1202
|
+
deprecated_legacy_json_field_conflicts: "bool" = betterproto2.field(6, betterproto2.TYPE_BOOL)
|
1203
|
+
"""
|
1204
|
+
Enable the legacy handling of JSON field name conflicts. This lowercases
|
1205
|
+
and strips underscored from the fields before comparison in proto3 only.
|
1206
|
+
The new behavior takes `json_name` into account and applies to proto2 as
|
1207
|
+
well.
|
1208
|
+
TODO Remove this legacy behavior once downstream teams have
|
1209
|
+
had time to migrate.
|
1210
|
+
"""
|
1211
|
+
|
1212
|
+
features: "Optional[FeatureSet]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, optional=True)
|
1213
|
+
"""
|
1214
|
+
Any features defined in the specific edition.
|
1215
|
+
"""
|
1216
|
+
|
1217
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
1218
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
1219
|
+
)
|
1220
|
+
"""
|
1221
|
+
The parser stores options it doesn't recognize here. See above.
|
1222
|
+
"""
|
1223
|
+
|
1224
|
+
def __post_init__(self) -> None:
|
1225
|
+
super().__post_init__()
|
1226
|
+
if self.is_set("deprecated_legacy_json_field_conflicts"):
|
1227
|
+
warnings.warn("EnumOptions.deprecated_legacy_json_field_conflicts is deprecated", DeprecationWarning)
|
1228
|
+
|
1229
|
+
|
1230
|
+
default_message_pool.register_message("google.protobuf", "EnumOptions", EnumOptions)
|
1231
|
+
|
1232
|
+
|
1233
|
+
@dataclass(eq=False, repr=False)
|
1234
|
+
class EnumValue(betterproto2.Message):
|
1235
|
+
"""
|
1236
|
+
Enum value definition.
|
1237
|
+
"""
|
1238
|
+
|
1239
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1240
|
+
"""
|
1241
|
+
Enum value name.
|
1242
|
+
"""
|
1243
|
+
|
1244
|
+
number: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
1245
|
+
"""
|
1246
|
+
Enum value number.
|
1247
|
+
"""
|
1248
|
+
|
1249
|
+
options: "List[Option]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, repeated=True)
|
1250
|
+
"""
|
1251
|
+
Protocol buffer options.
|
1252
|
+
"""
|
1253
|
+
|
1254
|
+
|
1255
|
+
default_message_pool.register_message("google.protobuf", "EnumValue", EnumValue)
|
1256
|
+
|
1257
|
+
|
1258
|
+
@dataclass(eq=False, repr=False)
|
1259
|
+
class EnumValueDescriptorProto(betterproto2.Message):
|
1260
|
+
"""
|
1261
|
+
Describes a value within an enum.
|
1262
|
+
"""
|
1263
|
+
|
1264
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1265
|
+
|
1266
|
+
number: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
1267
|
+
|
1268
|
+
options: "Optional[EnumValueOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
|
1269
|
+
|
1270
|
+
|
1271
|
+
default_message_pool.register_message("google.protobuf", "EnumValueDescriptorProto", EnumValueDescriptorProto)
|
1272
|
+
|
1273
|
+
|
1274
|
+
@dataclass(eq=False, repr=False)
|
1275
|
+
class EnumValueOptions(betterproto2.Message):
|
1276
|
+
deprecated: "bool" = betterproto2.field(1, betterproto2.TYPE_BOOL)
|
1277
|
+
"""
|
1278
|
+
Is this enum value deprecated?
|
1279
|
+
Depending on the target platform, this can emit Deprecated annotations
|
1280
|
+
for the enum value, or it will be completely ignored; in the very least,
|
1281
|
+
this is a formalization for deprecating enum values.
|
1282
|
+
"""
|
1283
|
+
|
1284
|
+
features: "Optional[FeatureSet]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
|
1285
|
+
"""
|
1286
|
+
Any features defined in the specific edition.
|
1287
|
+
"""
|
1288
|
+
|
1289
|
+
debug_redact: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
|
1290
|
+
"""
|
1291
|
+
Indicate that fields annotated with this enum value should not be printed
|
1292
|
+
out when using debug formats, e.g. when the field contains sensitive
|
1293
|
+
credentials.
|
1294
|
+
"""
|
1295
|
+
|
1296
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
1297
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
1298
|
+
)
|
1299
|
+
"""
|
1300
|
+
The parser stores options it doesn't recognize here. See above.
|
1301
|
+
"""
|
1302
|
+
|
1303
|
+
|
1304
|
+
default_message_pool.register_message("google.protobuf", "EnumValueOptions", EnumValueOptions)
|
1305
|
+
|
1306
|
+
|
1307
|
+
@dataclass(eq=False, repr=False)
|
1308
|
+
class ExtensionRangeOptions(betterproto2.Message):
|
1309
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
1310
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
1311
|
+
)
|
1312
|
+
"""
|
1313
|
+
The parser stores options it doesn't recognize here. See above.
|
1314
|
+
"""
|
1315
|
+
|
1316
|
+
declaration: "List[ExtensionRangeOptionsDeclaration]" = betterproto2.field(
|
1317
|
+
2, betterproto2.TYPE_MESSAGE, repeated=True
|
1318
|
+
)
|
1319
|
+
"""
|
1320
|
+
For external users: DO NOT USE. We are in the process of open sourcing
|
1321
|
+
extension declaration and executing internal cleanups before it can be
|
1322
|
+
used externally.
|
1323
|
+
"""
|
1324
|
+
|
1325
|
+
features: "Optional[FeatureSet]" = betterproto2.field(50, betterproto2.TYPE_MESSAGE, optional=True)
|
1326
|
+
"""
|
1327
|
+
Any features defined in the specific edition.
|
1328
|
+
"""
|
1329
|
+
|
1330
|
+
verification: "ExtensionRangeOptionsVerificationState" = betterproto2.field(
|
1331
|
+
3, betterproto2.TYPE_ENUM, default_factory=lambda: ExtensionRangeOptionsVerificationState.try_value(0)
|
1332
|
+
)
|
1333
|
+
"""
|
1334
|
+
The verification state of the range.
|
1335
|
+
TODO: flip the default to DECLARATION once all empty ranges
|
1336
|
+
are marked as UNVERIFIED.
|
1337
|
+
"""
|
1338
|
+
|
1339
|
+
|
1340
|
+
default_message_pool.register_message("google.protobuf", "ExtensionRangeOptions", ExtensionRangeOptions)
|
1341
|
+
|
1342
|
+
|
1343
|
+
@dataclass(eq=False, repr=False)
|
1344
|
+
class ExtensionRangeOptionsDeclaration(betterproto2.Message):
|
1345
|
+
number: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
|
1346
|
+
"""
|
1347
|
+
The extension number declared within the extension range.
|
1348
|
+
"""
|
1349
|
+
|
1350
|
+
full_name: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
1351
|
+
"""
|
1352
|
+
The fully-qualified name of the extension field. There must be a leading
|
1353
|
+
dot in front of the full name.
|
1354
|
+
"""
|
1355
|
+
|
1356
|
+
type: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
|
1357
|
+
"""
|
1358
|
+
The fully-qualified type name of the extension field. Unlike
|
1359
|
+
Metadata.type, Declaration.type must have a leading dot for messages
|
1360
|
+
and enums.
|
1361
|
+
"""
|
1362
|
+
|
1363
|
+
reserved: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
|
1364
|
+
"""
|
1365
|
+
If true, indicates that the number is reserved in the extension range,
|
1366
|
+
and any extension field with the number will fail to compile. Set this
|
1367
|
+
when a declared extension field is deleted.
|
1368
|
+
"""
|
1369
|
+
|
1370
|
+
repeated: "bool" = betterproto2.field(6, betterproto2.TYPE_BOOL)
|
1371
|
+
"""
|
1372
|
+
If true, indicates that the extension must be defined as repeated.
|
1373
|
+
Otherwise the extension must be defined as optional.
|
1374
|
+
"""
|
1375
|
+
|
1376
|
+
|
1377
|
+
default_message_pool.register_message(
|
1378
|
+
"google.protobuf", "ExtensionRangeOptions.Declaration", ExtensionRangeOptionsDeclaration
|
1379
|
+
)
|
1380
|
+
|
1381
|
+
|
1382
|
+
@dataclass(eq=False, repr=False)
|
1383
|
+
class FeatureSet(betterproto2.Message):
|
1384
|
+
"""
|
1385
|
+
===================================================================
|
1386
|
+
Features
|
1387
|
+
|
1388
|
+
TODO Enums in C++ gencode (and potentially other languages) are
|
1389
|
+
not well scoped. This means that each of the feature enums below can clash
|
1390
|
+
with each other. The short names we've chosen maximize call-site
|
1391
|
+
readability, but leave us very open to this scenario. A future feature will
|
1392
|
+
be designed and implemented to handle this, hopefully before we ever hit a
|
1393
|
+
conflict here.
|
1394
|
+
"""
|
1395
|
+
|
1396
|
+
field_presence: "FeatureSetFieldPresence" = betterproto2.field(
|
1397
|
+
1, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetFieldPresence.try_value(0)
|
1398
|
+
)
|
1399
|
+
|
1400
|
+
enum_type: "FeatureSetEnumType" = betterproto2.field(
|
1401
|
+
2, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetEnumType.try_value(0)
|
1402
|
+
)
|
1403
|
+
|
1404
|
+
repeated_field_encoding: "FeatureSetRepeatedFieldEncoding" = betterproto2.field(
|
1405
|
+
3, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetRepeatedFieldEncoding.try_value(0)
|
1406
|
+
)
|
1407
|
+
|
1408
|
+
utf8_validation: "FeatureSetUtf8Validation" = betterproto2.field(
|
1409
|
+
4, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetUtf8Validation.try_value(0)
|
1410
|
+
)
|
1411
|
+
|
1412
|
+
message_encoding: "FeatureSetMessageEncoding" = betterproto2.field(
|
1413
|
+
5, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetMessageEncoding.try_value(0)
|
1414
|
+
)
|
1415
|
+
|
1416
|
+
json_format: "FeatureSetJsonFormat" = betterproto2.field(
|
1417
|
+
6, betterproto2.TYPE_ENUM, default_factory=lambda: FeatureSetJsonFormat.try_value(0)
|
1418
|
+
)
|
1419
|
+
|
1420
|
+
|
1421
|
+
default_message_pool.register_message("google.protobuf", "FeatureSet", FeatureSet)
|
1422
|
+
|
1423
|
+
|
1424
|
+
@dataclass(eq=False, repr=False)
|
1425
|
+
class FeatureSetDefaults(betterproto2.Message):
|
1426
|
+
"""
|
1427
|
+
A compiled specification for the defaults of a set of features. These
|
1428
|
+
messages are generated from FeatureSet extensions and can be used to seed
|
1429
|
+
feature resolution. The resolution with this object becomes a simple search
|
1430
|
+
for the closest matching edition, followed by proto merges.
|
1431
|
+
"""
|
1432
|
+
|
1433
|
+
defaults: "List[FeatureSetDefaultsFeatureSetEditionDefault]" = betterproto2.field(
|
1434
|
+
1, betterproto2.TYPE_MESSAGE, repeated=True
|
1435
|
+
)
|
1436
|
+
|
1437
|
+
minimum_edition: "Edition" = betterproto2.field(
|
1438
|
+
4, betterproto2.TYPE_ENUM, default_factory=lambda: Edition.try_value(0)
|
1439
|
+
)
|
1440
|
+
"""
|
1441
|
+
The minimum supported edition (inclusive) when this was constructed.
|
1442
|
+
Editions before this will not have defaults.
|
1443
|
+
"""
|
1444
|
+
|
1445
|
+
maximum_edition: "Edition" = betterproto2.field(
|
1446
|
+
5, betterproto2.TYPE_ENUM, default_factory=lambda: Edition.try_value(0)
|
1447
|
+
)
|
1448
|
+
"""
|
1449
|
+
The maximum known edition (inclusive) when this was constructed. Editions
|
1450
|
+
after this will not have reliable defaults.
|
1451
|
+
"""
|
1452
|
+
|
1453
|
+
|
1454
|
+
default_message_pool.register_message("google.protobuf", "FeatureSetDefaults", FeatureSetDefaults)
|
1455
|
+
|
1456
|
+
|
1457
|
+
@dataclass(eq=False, repr=False)
|
1458
|
+
class FeatureSetDefaultsFeatureSetEditionDefault(betterproto2.Message):
|
1459
|
+
"""
|
1460
|
+
A map from every known edition with a unique set of defaults to its
|
1461
|
+
defaults. Not all editions may be contained here. For a given edition,
|
1462
|
+
the defaults at the closest matching edition ordered at or before it should
|
1463
|
+
be used. This field must be in strict ascending order by edition.
|
1464
|
+
"""
|
1465
|
+
|
1466
|
+
edition: "Edition" = betterproto2.field(3, betterproto2.TYPE_ENUM, default_factory=lambda: Edition.try_value(0))
|
1467
|
+
|
1468
|
+
features: "Optional[FeatureSet]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
|
1469
|
+
|
1470
|
+
|
1471
|
+
default_message_pool.register_message(
|
1472
|
+
"google.protobuf", "FeatureSetDefaults.FeatureSetEditionDefault", FeatureSetDefaultsFeatureSetEditionDefault
|
1473
|
+
)
|
1474
|
+
|
1475
|
+
|
1476
|
+
@dataclass(eq=False, repr=False)
|
1477
|
+
class Field(betterproto2.Message):
|
1478
|
+
"""
|
1479
|
+
A single field of a message type.
|
1480
|
+
"""
|
1481
|
+
|
1482
|
+
kind: "FieldKind" = betterproto2.field(1, betterproto2.TYPE_ENUM, default_factory=lambda: FieldKind.try_value(0))
|
1483
|
+
"""
|
1484
|
+
The field type.
|
1485
|
+
"""
|
1486
|
+
|
1487
|
+
cardinality: "FieldCardinality" = betterproto2.field(
|
1488
|
+
2, betterproto2.TYPE_ENUM, default_factory=lambda: FieldCardinality.try_value(0)
|
1489
|
+
)
|
1490
|
+
"""
|
1491
|
+
The field cardinality.
|
1492
|
+
"""
|
1493
|
+
|
1494
|
+
number: "int" = betterproto2.field(3, betterproto2.TYPE_INT32)
|
1495
|
+
"""
|
1496
|
+
The field number.
|
1497
|
+
"""
|
1498
|
+
|
1499
|
+
name: "str" = betterproto2.field(4, betterproto2.TYPE_STRING)
|
1500
|
+
"""
|
1501
|
+
The field name.
|
1502
|
+
"""
|
1503
|
+
|
1504
|
+
type_url: "str" = betterproto2.field(6, betterproto2.TYPE_STRING)
|
1505
|
+
"""
|
1506
|
+
The field type URL, without the scheme, for message or enumeration
|
1507
|
+
types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
|
1508
|
+
"""
|
1509
|
+
|
1510
|
+
oneof_index: "int | None" = betterproto2.field(7, betterproto2.TYPE_INT32, optional=True)
|
1511
|
+
"""
|
1512
|
+
The index of the field type in `Type.oneofs`, for message or enumeration
|
1513
|
+
types. The first type has index 1; zero means the type is not in the list.
|
1514
|
+
"""
|
1515
|
+
|
1516
|
+
packed: "bool" = betterproto2.field(8, betterproto2.TYPE_BOOL)
|
1517
|
+
"""
|
1518
|
+
Whether to use alternative packed wire representation.
|
1519
|
+
"""
|
1520
|
+
|
1521
|
+
options: "List[Option]" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, repeated=True)
|
1522
|
+
"""
|
1523
|
+
The protocol buffer options.
|
1524
|
+
"""
|
1525
|
+
|
1526
|
+
json_name: "str" = betterproto2.field(10, betterproto2.TYPE_STRING)
|
1527
|
+
"""
|
1528
|
+
The field JSON name.
|
1529
|
+
"""
|
1530
|
+
|
1531
|
+
default_value: "str" = betterproto2.field(11, betterproto2.TYPE_STRING)
|
1532
|
+
"""
|
1533
|
+
The string value of the default value of this field. Proto2 syntax only.
|
1534
|
+
"""
|
1535
|
+
|
1536
|
+
|
1537
|
+
default_message_pool.register_message("google.protobuf", "Field", Field)
|
1538
|
+
|
1539
|
+
|
1540
|
+
@dataclass(eq=False, repr=False)
|
1541
|
+
class FieldDescriptorProto(betterproto2.Message):
|
1542
|
+
"""
|
1543
|
+
Describes a field within a message.
|
1544
|
+
"""
|
1545
|
+
|
1546
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1547
|
+
|
1548
|
+
number: "int" = betterproto2.field(3, betterproto2.TYPE_INT32)
|
1549
|
+
|
1550
|
+
label: "FieldDescriptorProtoLabel" = betterproto2.field(
|
1551
|
+
4, betterproto2.TYPE_ENUM, default_factory=lambda: FieldDescriptorProtoLabel.try_value(0)
|
1552
|
+
)
|
1553
|
+
|
1554
|
+
type: "FieldDescriptorProtoType" = betterproto2.field(
|
1555
|
+
5, betterproto2.TYPE_ENUM, default_factory=lambda: FieldDescriptorProtoType.try_value(0)
|
1556
|
+
)
|
1557
|
+
"""
|
1558
|
+
If type_name is set, this need not be set. If both this and type_name
|
1559
|
+
are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
|
1560
|
+
"""
|
1561
|
+
|
1562
|
+
type_name: "str" = betterproto2.field(6, betterproto2.TYPE_STRING)
|
1563
|
+
"""
|
1564
|
+
For message and enum types, this is the name of the type. If the name
|
1565
|
+
starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
|
1566
|
+
rules are used to find the type (i.e. first the nested types within this
|
1567
|
+
message are searched, then within the parent, on up to the root
|
1568
|
+
namespace).
|
1569
|
+
"""
|
1570
|
+
|
1571
|
+
extendee: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
1572
|
+
"""
|
1573
|
+
For extensions, this is the name of the type being extended. It is
|
1574
|
+
resolved in the same manner as type_name.
|
1575
|
+
"""
|
1576
|
+
|
1577
|
+
default_value: "str" = betterproto2.field(7, betterproto2.TYPE_STRING)
|
1578
|
+
"""
|
1579
|
+
For numeric types, contains the original text representation of the value.
|
1580
|
+
For booleans, "true" or "false".
|
1581
|
+
For strings, contains the default text contents (not escaped in any way).
|
1582
|
+
For bytes, contains the C escaped value. All bytes >= 128 are escaped.
|
1583
|
+
"""
|
1584
|
+
|
1585
|
+
oneof_index: "int | None" = betterproto2.field(9, betterproto2.TYPE_INT32, optional=True)
|
1586
|
+
"""
|
1587
|
+
If set, gives the index of a oneof in the containing type's oneof_decl
|
1588
|
+
list. This field is a member of that oneof.
|
1589
|
+
"""
|
1590
|
+
|
1591
|
+
json_name: "str" = betterproto2.field(10, betterproto2.TYPE_STRING)
|
1592
|
+
"""
|
1593
|
+
JSON name of this field. The value is set by protocol compiler. If the
|
1594
|
+
user has set a "json_name" option on this field, that option's value
|
1595
|
+
will be used. Otherwise, it's deduced from the field's name by converting
|
1596
|
+
it to camelCase.
|
1597
|
+
"""
|
1598
|
+
|
1599
|
+
options: "Optional[FieldOptions]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
|
1600
|
+
|
1601
|
+
proto3_optional: "bool" = betterproto2.field(17, betterproto2.TYPE_BOOL)
|
1602
|
+
"""
|
1603
|
+
If true, this is a proto3 "optional". When a proto3 field is optional, it
|
1604
|
+
tracks presence regardless of field type.
|
1605
|
+
|
1606
|
+
When proto3_optional is true, this field must be belong to a oneof to
|
1607
|
+
signal to old proto3 clients that presence is tracked for this field. This
|
1608
|
+
oneof is known as a "synthetic" oneof, and this field must be its sole
|
1609
|
+
member (each proto3 optional field gets its own synthetic oneof). Synthetic
|
1610
|
+
oneofs exist in the descriptor only, and do not generate any API. Synthetic
|
1611
|
+
oneofs must be ordered after all "real" oneofs.
|
1612
|
+
|
1613
|
+
For message fields, proto3_optional doesn't create any semantic change,
|
1614
|
+
since non-repeated message fields always track presence. However it still
|
1615
|
+
indicates the semantic detail of whether the user wrote "optional" or not.
|
1616
|
+
This can be useful for round-tripping the .proto file. For consistency we
|
1617
|
+
give message fields a synthetic oneof also, even though it is not required
|
1618
|
+
to track presence. This is especially important because the parser can't
|
1619
|
+
tell if a field is a message or an enum, so it must always create a
|
1620
|
+
synthetic oneof.
|
1621
|
+
|
1622
|
+
Proto2 optional fields do not set this flag, because they already indicate
|
1623
|
+
optional with `LABEL_OPTIONAL`.
|
1624
|
+
"""
|
1625
|
+
|
1626
|
+
|
1627
|
+
default_message_pool.register_message("google.protobuf", "FieldDescriptorProto", FieldDescriptorProto)
|
1628
|
+
|
1629
|
+
|
1630
|
+
@dataclass(eq=False, repr=False)
|
1631
|
+
class FieldMask(betterproto2.Message):
|
1632
|
+
"""
|
1633
|
+
`FieldMask` represents a set of symbolic field paths, for example:
|
1634
|
+
|
1635
|
+
paths: "f.a"
|
1636
|
+
paths: "f.b.d"
|
1637
|
+
|
1638
|
+
Here `f` represents a field in some root message, `a` and `b`
|
1639
|
+
fields in the message found in `f`, and `d` a field found in the
|
1640
|
+
message in `f.b`.
|
1641
|
+
|
1642
|
+
Field masks are used to specify a subset of fields that should be
|
1643
|
+
returned by a get operation or modified by an update operation.
|
1644
|
+
Field masks also have a custom JSON encoding (see below).
|
1645
|
+
|
1646
|
+
# Field Masks in Projections
|
1647
|
+
|
1648
|
+
When used in the context of a projection, a response message or
|
1649
|
+
sub-message is filtered by the API to only contain those fields as
|
1650
|
+
specified in the mask. For example, if the mask in the previous
|
1651
|
+
example is applied to a response message as follows:
|
1652
|
+
|
1653
|
+
f {
|
1654
|
+
a : 22
|
1655
|
+
b {
|
1656
|
+
d : 1
|
1657
|
+
x : 2
|
1658
|
+
}
|
1659
|
+
y : 13
|
1660
|
+
}
|
1661
|
+
z: 8
|
1662
|
+
|
1663
|
+
The result will not contain specific values for fields x,y and z
|
1664
|
+
(their value will be set to the default, and omitted in proto text
|
1665
|
+
output):
|
1666
|
+
|
1667
|
+
f {
|
1668
|
+
a : 22
|
1669
|
+
b {
|
1670
|
+
d : 1
|
1671
|
+
}
|
1672
|
+
}
|
1673
|
+
|
1674
|
+
A repeated field is not allowed except at the last position of a
|
1675
|
+
paths string.
|
1676
|
+
|
1677
|
+
If a FieldMask object is not present in a get operation, the
|
1678
|
+
operation applies to all fields (as if a FieldMask of all fields
|
1679
|
+
had been specified).
|
1680
|
+
|
1681
|
+
Note that a field mask does not necessarily apply to the
|
1682
|
+
top-level response message. In case of a REST get operation, the
|
1683
|
+
field mask applies directly to the response, but in case of a REST
|
1684
|
+
list operation, the mask instead applies to each individual message
|
1685
|
+
in the returned resource list. In case of a REST custom method,
|
1686
|
+
other definitions may be used. Where the mask applies will be
|
1687
|
+
clearly documented together with its declaration in the API. In
|
1688
|
+
any case, the effect on the returned resource/resources is required
|
1689
|
+
behavior for APIs.
|
1690
|
+
|
1691
|
+
# Field Masks in Update Operations
|
1692
|
+
|
1693
|
+
A field mask in update operations specifies which fields of the
|
1694
|
+
targeted resource are going to be updated. The API is required
|
1695
|
+
to only change the values of the fields as specified in the mask
|
1696
|
+
and leave the others untouched. If a resource is passed in to
|
1697
|
+
describe the updated values, the API ignores the values of all
|
1698
|
+
fields not covered by the mask.
|
1699
|
+
|
1700
|
+
If a repeated field is specified for an update operation, new values will
|
1701
|
+
be appended to the existing repeated field in the target resource. Note that
|
1702
|
+
a repeated field is only allowed in the last position of a `paths` string.
|
1703
|
+
|
1704
|
+
If a sub-message is specified in the last position of the field mask for an
|
1705
|
+
update operation, then new value will be merged into the existing sub-message
|
1706
|
+
in the target resource.
|
1707
|
+
|
1708
|
+
For example, given the target message:
|
1709
|
+
|
1710
|
+
f {
|
1711
|
+
b {
|
1712
|
+
d: 1
|
1713
|
+
x: 2
|
1714
|
+
}
|
1715
|
+
c: [1]
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
And an update message:
|
1719
|
+
|
1720
|
+
f {
|
1721
|
+
b {
|
1722
|
+
d: 10
|
1723
|
+
}
|
1724
|
+
c: [2]
|
1725
|
+
}
|
1726
|
+
|
1727
|
+
then if the field mask is:
|
1728
|
+
|
1729
|
+
paths: ["f.b", "f.c"]
|
1730
|
+
|
1731
|
+
then the result will be:
|
1732
|
+
|
1733
|
+
f {
|
1734
|
+
b {
|
1735
|
+
d: 10
|
1736
|
+
x: 2
|
1737
|
+
}
|
1738
|
+
c: [1, 2]
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
An implementation may provide options to override this default behavior for
|
1742
|
+
repeated and message fields.
|
1743
|
+
|
1744
|
+
In order to reset a field's value to the default, the field must
|
1745
|
+
be in the mask and set to the default value in the provided resource.
|
1746
|
+
Hence, in order to reset all fields of a resource, provide a default
|
1747
|
+
instance of the resource and set all fields in the mask, or do
|
1748
|
+
not provide a mask as described below.
|
1749
|
+
|
1750
|
+
If a field mask is not present on update, the operation applies to
|
1751
|
+
all fields (as if a field mask of all fields has been specified).
|
1752
|
+
Note that in the presence of schema evolution, this may mean that
|
1753
|
+
fields the client does not know and has therefore not filled into
|
1754
|
+
the request will be reset to their default. If this is unwanted
|
1755
|
+
behavior, a specific service may require a client to always specify
|
1756
|
+
a field mask, producing an error if not.
|
1757
|
+
|
1758
|
+
As with get operations, the location of the resource which
|
1759
|
+
describes the updated values in the request message depends on the
|
1760
|
+
operation kind. In any case, the effect of the field mask is
|
1761
|
+
required to be honored by the API.
|
1762
|
+
|
1763
|
+
## Considerations for HTTP REST
|
1764
|
+
|
1765
|
+
The HTTP kind of an update operation which uses a field mask must
|
1766
|
+
be set to PATCH instead of PUT in order to satisfy HTTP semantics
|
1767
|
+
(PUT must only be used for full updates).
|
1768
|
+
|
1769
|
+
# JSON Encoding of Field Masks
|
1770
|
+
|
1771
|
+
In JSON, a field mask is encoded as a single string where paths are
|
1772
|
+
separated by a comma. Fields name in each path are converted
|
1773
|
+
to/from lower-camel naming conventions.
|
1774
|
+
|
1775
|
+
As an example, consider the following message declarations:
|
1776
|
+
|
1777
|
+
message Profile {
|
1778
|
+
User user = 1;
|
1779
|
+
Photo photo = 2;
|
1780
|
+
}
|
1781
|
+
message User {
|
1782
|
+
string display_name = 1;
|
1783
|
+
string address = 2;
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
In proto a field mask for `Profile` may look as such:
|
1787
|
+
|
1788
|
+
mask {
|
1789
|
+
paths: "user.display_name"
|
1790
|
+
paths: "photo"
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
In JSON, the same mask is represented as below:
|
1794
|
+
|
1795
|
+
{
|
1796
|
+
mask: "user.displayName,photo"
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
# Field Masks and Oneof Fields
|
1800
|
+
|
1801
|
+
Field masks treat fields in oneofs just as regular fields. Consider the
|
1802
|
+
following message:
|
1803
|
+
|
1804
|
+
message SampleMessage {
|
1805
|
+
oneof test_oneof {
|
1806
|
+
string name = 4;
|
1807
|
+
SubMessage sub_message = 9;
|
1808
|
+
}
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
The field mask can be:
|
1812
|
+
|
1813
|
+
mask {
|
1814
|
+
paths: "name"
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
Or:
|
1818
|
+
|
1819
|
+
mask {
|
1820
|
+
paths: "sub_message"
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
Note that oneof type names ("test_oneof" in this case) cannot be used in
|
1824
|
+
paths.
|
1825
|
+
|
1826
|
+
## Field Mask Verification
|
1827
|
+
|
1828
|
+
The implementation of any API method which has a FieldMask type field in the
|
1829
|
+
request should verify the included field paths, and return an
|
1830
|
+
`INVALID_ARGUMENT` error if any path is unmappable.
|
1831
|
+
"""
|
1832
|
+
|
1833
|
+
paths: "List[str]" = betterproto2.field(1, betterproto2.TYPE_STRING, repeated=True)
|
1834
|
+
"""
|
1835
|
+
The set of field mask paths.
|
1836
|
+
"""
|
1837
|
+
|
1838
|
+
|
1839
|
+
default_message_pool.register_message("google.protobuf", "FieldMask", FieldMask)
|
1840
|
+
|
1841
|
+
|
1842
|
+
@dataclass(eq=False, repr=False)
|
1843
|
+
class FieldOptions(betterproto2.Message):
|
1844
|
+
ctype: "FieldOptionsCType" = betterproto2.field(
|
1845
|
+
1, betterproto2.TYPE_ENUM, default_factory=lambda: FieldOptionsCType.try_value(0)
|
1846
|
+
)
|
1847
|
+
"""
|
1848
|
+
The ctype option instructs the C++ code generator to use a different
|
1849
|
+
representation of the field than it normally would. See the specific
|
1850
|
+
options below. This option is only implemented to support use of
|
1851
|
+
[ctype=CORD] and [ctype=STRING] (the default) on non-repeated fields of
|
1852
|
+
type "bytes" in the open source release -- sorry, we'll try to include
|
1853
|
+
other types in a future version!
|
1854
|
+
"""
|
1855
|
+
|
1856
|
+
packed: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
|
1857
|
+
"""
|
1858
|
+
The packed option can be enabled for repeated primitive fields to enable
|
1859
|
+
a more efficient representation on the wire. Rather than repeatedly
|
1860
|
+
writing the tag and type for each element, the entire array is encoded as
|
1861
|
+
a single length-delimited blob. In proto3, only explicit setting it to
|
1862
|
+
false will avoid using packed encoding. This option is prohibited in
|
1863
|
+
Editions, but the `repeated_field_encoding` feature can be used to control
|
1864
|
+
the behavior.
|
1865
|
+
"""
|
1866
|
+
|
1867
|
+
jstype: "FieldOptionsJsType" = betterproto2.field(
|
1868
|
+
6, betterproto2.TYPE_ENUM, default_factory=lambda: FieldOptionsJsType.try_value(0)
|
1869
|
+
)
|
1870
|
+
"""
|
1871
|
+
The jstype option determines the JavaScript type used for values of the
|
1872
|
+
field. The option is permitted only for 64 bit integral and fixed types
|
1873
|
+
(int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
|
1874
|
+
is represented as JavaScript string, which avoids loss of precision that
|
1875
|
+
can happen when a large value is converted to a floating point JavaScript.
|
1876
|
+
Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
|
1877
|
+
use the JavaScript "number" type. The behavior of the default option
|
1878
|
+
JS_NORMAL is implementation dependent.
|
1879
|
+
|
1880
|
+
This option is an enum to permit additional types to be added, e.g.
|
1881
|
+
goog.math.Integer.
|
1882
|
+
"""
|
1883
|
+
|
1884
|
+
lazy: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
|
1885
|
+
"""
|
1886
|
+
Should this field be parsed lazily? Lazy applies only to message-type
|
1887
|
+
fields. It means that when the outer message is initially parsed, the
|
1888
|
+
inner message's contents will not be parsed but instead stored in encoded
|
1889
|
+
form. The inner message will actually be parsed when it is first accessed.
|
1890
|
+
|
1891
|
+
This is only a hint. Implementations are free to choose whether to use
|
1892
|
+
eager or lazy parsing regardless of the value of this option. However,
|
1893
|
+
setting this option true suggests that the protocol author believes that
|
1894
|
+
using lazy parsing on this field is worth the additional bookkeeping
|
1895
|
+
overhead typically needed to implement it.
|
1896
|
+
|
1897
|
+
This option does not affect the public interface of any generated code;
|
1898
|
+
all method signatures remain the same. Furthermore, thread-safety of the
|
1899
|
+
interface is not affected by this option; const methods remain safe to
|
1900
|
+
call from multiple threads concurrently, while non-const methods continue
|
1901
|
+
to require exclusive access.
|
1902
|
+
|
1903
|
+
Note that implementations may choose not to check required fields within
|
1904
|
+
a lazy sub-message. That is, calling IsInitialized() on the outer message
|
1905
|
+
may return true even if the inner message has missing required fields.
|
1906
|
+
This is necessary because otherwise the inner message would have to be
|
1907
|
+
parsed in order to perform the check, defeating the purpose of lazy
|
1908
|
+
parsing. An implementation which chooses not to check required fields
|
1909
|
+
must be consistent about it. That is, for any particular sub-message, the
|
1910
|
+
implementation must either *always* check its required fields, or *never*
|
1911
|
+
check its required fields, regardless of whether or not the message has
|
1912
|
+
been parsed.
|
1913
|
+
|
1914
|
+
As of May 2022, lazy verifies the contents of the byte stream during
|
1915
|
+
parsing. An invalid byte stream will cause the overall parsing to fail.
|
1916
|
+
"""
|
1917
|
+
|
1918
|
+
unverified_lazy: "bool" = betterproto2.field(15, betterproto2.TYPE_BOOL)
|
1919
|
+
"""
|
1920
|
+
unverified_lazy does no correctness checks on the byte stream. This should
|
1921
|
+
only be used where lazy with verification is prohibitive for performance
|
1922
|
+
reasons.
|
1923
|
+
"""
|
1924
|
+
|
1925
|
+
deprecated: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
|
1926
|
+
"""
|
1927
|
+
Is this field deprecated?
|
1928
|
+
Depending on the target platform, this can emit Deprecated annotations
|
1929
|
+
for accessors, or it will be completely ignored; in the very least, this
|
1930
|
+
is a formalization for deprecating fields.
|
1931
|
+
"""
|
1932
|
+
|
1933
|
+
weak: "bool" = betterproto2.field(10, betterproto2.TYPE_BOOL)
|
1934
|
+
"""
|
1935
|
+
For Google-internal migration only. Do not use.
|
1936
|
+
"""
|
1937
|
+
|
1938
|
+
debug_redact: "bool" = betterproto2.field(16, betterproto2.TYPE_BOOL)
|
1939
|
+
"""
|
1940
|
+
Indicate that the field value should not be printed out when using debug
|
1941
|
+
formats, e.g. when the field contains sensitive credentials.
|
1942
|
+
"""
|
1943
|
+
|
1944
|
+
retention: "FieldOptionsOptionRetention" = betterproto2.field(
|
1945
|
+
17, betterproto2.TYPE_ENUM, default_factory=lambda: FieldOptionsOptionRetention.try_value(0)
|
1946
|
+
)
|
1947
|
+
|
1948
|
+
targets: "List[FieldOptionsOptionTargetType]" = betterproto2.field(19, betterproto2.TYPE_ENUM, repeated=True)
|
1949
|
+
|
1950
|
+
edition_defaults: "List[FieldOptionsEditionDefault]" = betterproto2.field(
|
1951
|
+
20, betterproto2.TYPE_MESSAGE, repeated=True
|
1952
|
+
)
|
1953
|
+
|
1954
|
+
features: "Optional[FeatureSet]" = betterproto2.field(21, betterproto2.TYPE_MESSAGE, optional=True)
|
1955
|
+
"""
|
1956
|
+
Any features defined in the specific edition.
|
1957
|
+
"""
|
1958
|
+
|
1959
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
1960
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
1961
|
+
)
|
1962
|
+
"""
|
1963
|
+
The parser stores options it doesn't recognize here. See above.
|
1964
|
+
"""
|
1965
|
+
|
1966
|
+
|
1967
|
+
default_message_pool.register_message("google.protobuf", "FieldOptions", FieldOptions)
|
1968
|
+
|
1969
|
+
|
1970
|
+
@dataclass(eq=False, repr=False)
|
1971
|
+
class FieldOptionsEditionDefault(betterproto2.Message):
|
1972
|
+
edition: "Edition" = betterproto2.field(3, betterproto2.TYPE_ENUM, default_factory=lambda: Edition.try_value(0))
|
1973
|
+
|
1974
|
+
value: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
1975
|
+
"""
|
1976
|
+
Textproto value.
|
1977
|
+
"""
|
1978
|
+
|
1979
|
+
|
1980
|
+
default_message_pool.register_message("google.protobuf", "FieldOptions.EditionDefault", FieldOptionsEditionDefault)
|
1981
|
+
|
1982
|
+
|
1983
|
+
@dataclass(eq=False, repr=False)
|
1984
|
+
class FileDescriptorProto(betterproto2.Message):
|
1985
|
+
"""
|
1986
|
+
Describes a complete .proto file.
|
1987
|
+
"""
|
1988
|
+
|
1989
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
1990
|
+
"""
|
1991
|
+
file name, relative to root of source tree
|
1992
|
+
"""
|
1993
|
+
|
1994
|
+
package: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
1995
|
+
"""
|
1996
|
+
e.g. "foo", "foo.bar", etc.
|
1997
|
+
"""
|
1998
|
+
|
1999
|
+
dependency: "List[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
|
2000
|
+
"""
|
2001
|
+
Names of files imported by this file.
|
2002
|
+
"""
|
2003
|
+
|
2004
|
+
public_dependency: "List[int]" = betterproto2.field(10, betterproto2.TYPE_INT32, repeated=True)
|
2005
|
+
"""
|
2006
|
+
Indexes of the public imported files in the dependency list above.
|
2007
|
+
"""
|
2008
|
+
|
2009
|
+
weak_dependency: "List[int]" = betterproto2.field(11, betterproto2.TYPE_INT32, repeated=True)
|
2010
|
+
"""
|
2011
|
+
Indexes of the weak imported files in the dependency list.
|
2012
|
+
For Google-internal migration only. Do not use.
|
2013
|
+
"""
|
2014
|
+
|
2015
|
+
message_type: "List[DescriptorProto]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
|
2016
|
+
"""
|
2017
|
+
All top-level definitions in this file.
|
2018
|
+
"""
|
2019
|
+
|
2020
|
+
enum_type: "List[EnumDescriptorProto]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, repeated=True)
|
2021
|
+
|
2022
|
+
service: "List[ServiceDescriptorProto]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
|
2023
|
+
|
2024
|
+
extension: "List[FieldDescriptorProto]" = betterproto2.field(7, betterproto2.TYPE_MESSAGE, repeated=True)
|
2025
|
+
|
2026
|
+
options: "Optional[FileOptions]" = betterproto2.field(8, betterproto2.TYPE_MESSAGE, optional=True)
|
2027
|
+
|
2028
|
+
source_code_info: "Optional[SourceCodeInfo]" = betterproto2.field(9, betterproto2.TYPE_MESSAGE, optional=True)
|
2029
|
+
"""
|
2030
|
+
This field contains optional information about the original source code.
|
2031
|
+
You may safely remove this entire field without harming runtime
|
2032
|
+
functionality of the descriptors -- the information is needed only by
|
2033
|
+
development tools.
|
2034
|
+
"""
|
2035
|
+
|
2036
|
+
syntax: "str" = betterproto2.field(12, betterproto2.TYPE_STRING)
|
2037
|
+
"""
|
2038
|
+
The syntax of the proto file.
|
2039
|
+
The supported values are "proto2", "proto3", and "editions".
|
2040
|
+
|
2041
|
+
If `edition` is present, this value must be "editions".
|
2042
|
+
"""
|
2043
|
+
|
2044
|
+
edition: "Edition" = betterproto2.field(14, betterproto2.TYPE_ENUM, default_factory=lambda: Edition.try_value(0))
|
2045
|
+
"""
|
2046
|
+
The edition of the proto file.
|
2047
|
+
"""
|
2048
|
+
|
2049
|
+
|
2050
|
+
default_message_pool.register_message("google.protobuf", "FileDescriptorProto", FileDescriptorProto)
|
2051
|
+
|
2052
|
+
|
2053
|
+
@dataclass(eq=False, repr=False)
|
2054
|
+
class FileDescriptorSet(betterproto2.Message):
|
2055
|
+
"""
|
2056
|
+
The protocol compiler can output a FileDescriptorSet containing the .proto
|
2057
|
+
files it parses.
|
2058
|
+
"""
|
2059
|
+
|
2060
|
+
file: "List[FileDescriptorProto]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
|
2061
|
+
|
2062
|
+
|
2063
|
+
default_message_pool.register_message("google.protobuf", "FileDescriptorSet", FileDescriptorSet)
|
2064
|
+
|
2065
|
+
|
2066
|
+
@dataclass(eq=False, repr=False)
|
2067
|
+
class FileOptions(betterproto2.Message):
|
2068
|
+
"""
|
2069
|
+
===================================================================
|
2070
|
+
Options
|
2071
|
+
|
2072
|
+
Each of the definitions above may have "options" attached. These are
|
2073
|
+
just annotations which may cause code to be generated slightly differently
|
2074
|
+
or may contain hints for code that manipulates protocol messages.
|
2075
|
+
|
2076
|
+
Clients may define custom options as extensions of the *Options messages.
|
2077
|
+
These extensions may not yet be known at parsing time, so the parser cannot
|
2078
|
+
store the values in them. Instead it stores them in a field in the *Options
|
2079
|
+
message called uninterpreted_option. This field must have the same name
|
2080
|
+
across all *Options messages. We then use this field to populate the
|
2081
|
+
extensions when we build a descriptor, at which point all protos have been
|
2082
|
+
parsed and so all extensions are known.
|
2083
|
+
|
2084
|
+
Extension numbers for custom options may be chosen as follows:
|
2085
|
+
* For options which will only be used within a single application or
|
2086
|
+
organization, or for experimental options, use field numbers 50000
|
2087
|
+
through 99999. It is up to you to ensure that you do not use the
|
2088
|
+
same number for multiple options.
|
2089
|
+
* For options which will be published and used publicly by multiple
|
2090
|
+
independent entities, e-mail protobuf-global-extension-registry@google.com
|
2091
|
+
to reserve extension numbers. Simply provide your project name (e.g.
|
2092
|
+
Objective-C plugin) and your project website (if available) -- there's no
|
2093
|
+
need to explain how you intend to use them. Usually you only need one
|
2094
|
+
extension number. You can declare multiple options with only one extension
|
2095
|
+
number by putting them in a sub-message. See the Custom Options section of
|
2096
|
+
the docs for examples:
|
2097
|
+
https://developers.google.com/protocol-buffers/docs/proto#options
|
2098
|
+
If this turns out to be popular, a web service will be set up
|
2099
|
+
to automatically assign option numbers.
|
2100
|
+
"""
|
2101
|
+
|
2102
|
+
java_package: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2103
|
+
"""
|
2104
|
+
Sets the Java package where classes generated from this .proto will be
|
2105
|
+
placed. By default, the proto package is used, but this is often
|
2106
|
+
inappropriate because proto packages do not normally start with backwards
|
2107
|
+
domain names.
|
2108
|
+
"""
|
2109
|
+
|
2110
|
+
java_outer_classname: "str" = betterproto2.field(8, betterproto2.TYPE_STRING)
|
2111
|
+
"""
|
2112
|
+
Controls the name of the wrapper Java class generated for the .proto file.
|
2113
|
+
That class will always contain the .proto file's getDescriptor() method as
|
2114
|
+
well as any top-level extensions defined in the .proto file.
|
2115
|
+
If java_multiple_files is disabled, then all the other classes from the
|
2116
|
+
.proto file will be nested inside the single wrapper outer class.
|
2117
|
+
"""
|
2118
|
+
|
2119
|
+
java_multiple_files: "bool" = betterproto2.field(10, betterproto2.TYPE_BOOL)
|
2120
|
+
"""
|
2121
|
+
If enabled, then the Java code generator will generate a separate .java
|
2122
|
+
file for each top-level message, enum, and service defined in the .proto
|
2123
|
+
file. Thus, these types will *not* be nested inside the wrapper class
|
2124
|
+
named by java_outer_classname. However, the wrapper class will still be
|
2125
|
+
generated to contain the file's getDescriptor() method as well as any
|
2126
|
+
top-level extensions defined in the file.
|
2127
|
+
"""
|
2128
|
+
|
2129
|
+
java_generate_equals_and_hash: "bool" = betterproto2.field(20, betterproto2.TYPE_BOOL)
|
2130
|
+
"""
|
2131
|
+
This option does nothing.
|
2132
|
+
"""
|
2133
|
+
|
2134
|
+
java_string_check_utf8: "bool" = betterproto2.field(27, betterproto2.TYPE_BOOL)
|
2135
|
+
"""
|
2136
|
+
If set true, then the Java2 code generator will generate code that
|
2137
|
+
throws an exception whenever an attempt is made to assign a non-UTF-8
|
2138
|
+
byte sequence to a string field.
|
2139
|
+
Message reflection will do the same.
|
2140
|
+
However, an extension field still accepts non-UTF-8 byte sequences.
|
2141
|
+
This option has no effect on when used with the lite runtime.
|
2142
|
+
"""
|
2143
|
+
|
2144
|
+
optimize_for: "FileOptionsOptimizeMode" = betterproto2.field(
|
2145
|
+
9, betterproto2.TYPE_ENUM, default_factory=lambda: FileOptionsOptimizeMode.try_value(0)
|
2146
|
+
)
|
2147
|
+
|
2148
|
+
go_package: "str" = betterproto2.field(11, betterproto2.TYPE_STRING)
|
2149
|
+
"""
|
2150
|
+
Sets the Go package where structs generated from this .proto will be
|
2151
|
+
placed. If omitted, the Go package will be derived from the following:
|
2152
|
+
- The basename of the package import path, if provided.
|
2153
|
+
- Otherwise, the package statement in the .proto file, if present.
|
2154
|
+
- Otherwise, the basename of the .proto file, without extension.
|
2155
|
+
"""
|
2156
|
+
|
2157
|
+
cc_generic_services: "bool" = betterproto2.field(16, betterproto2.TYPE_BOOL)
|
2158
|
+
"""
|
2159
|
+
Should generic services be generated in each language? "Generic" services
|
2160
|
+
are not specific to any particular RPC system. They are generated by the
|
2161
|
+
main code generators in each language (without additional plugins).
|
2162
|
+
Generic services were the only kind of service generation supported by
|
2163
|
+
early versions of google.protobuf.
|
2164
|
+
|
2165
|
+
Generic services are now considered deprecated in favor of using plugins
|
2166
|
+
that generate code specific to your particular RPC system. Therefore,
|
2167
|
+
these default to false. Old code which depends on generic services should
|
2168
|
+
explicitly set them to true.
|
2169
|
+
"""
|
2170
|
+
|
2171
|
+
java_generic_services: "bool" = betterproto2.field(17, betterproto2.TYPE_BOOL)
|
2172
|
+
|
2173
|
+
py_generic_services: "bool" = betterproto2.field(18, betterproto2.TYPE_BOOL)
|
2174
|
+
|
2175
|
+
php_generic_services: "bool" = betterproto2.field(42, betterproto2.TYPE_BOOL)
|
2176
|
+
|
2177
|
+
deprecated: "bool" = betterproto2.field(23, betterproto2.TYPE_BOOL)
|
2178
|
+
"""
|
2179
|
+
Is this file deprecated?
|
2180
|
+
Depending on the target platform, this can emit Deprecated annotations
|
2181
|
+
for everything in the file, or it will be completely ignored; in the very
|
2182
|
+
least, this is a formalization for deprecating files.
|
2183
|
+
"""
|
2184
|
+
|
2185
|
+
cc_enable_arenas: "bool" = betterproto2.field(31, betterproto2.TYPE_BOOL)
|
2186
|
+
"""
|
2187
|
+
Enables the use of arenas for the proto messages in this file. This applies
|
2188
|
+
only to generated classes for C++.
|
2189
|
+
"""
|
2190
|
+
|
2191
|
+
objc_class_prefix: "str" = betterproto2.field(36, betterproto2.TYPE_STRING)
|
2192
|
+
"""
|
2193
|
+
Sets the objective c class prefix which is prepended to all objective c
|
2194
|
+
generated classes from this .proto. There is no default.
|
2195
|
+
"""
|
2196
|
+
|
2197
|
+
csharp_namespace: "str" = betterproto2.field(37, betterproto2.TYPE_STRING)
|
2198
|
+
"""
|
2199
|
+
Namespace for generated classes; defaults to the package.
|
2200
|
+
"""
|
2201
|
+
|
2202
|
+
swift_prefix: "str" = betterproto2.field(39, betterproto2.TYPE_STRING)
|
2203
|
+
"""
|
2204
|
+
By default Swift generators will take the proto package and CamelCase it
|
2205
|
+
replacing '.' with underscore and use that to prefix the types/symbols
|
2206
|
+
defined. When this options is provided, they will use this value instead
|
2207
|
+
to prefix the types/symbols defined.
|
2208
|
+
"""
|
2209
|
+
|
2210
|
+
php_class_prefix: "str" = betterproto2.field(40, betterproto2.TYPE_STRING)
|
2211
|
+
"""
|
2212
|
+
Sets the php class prefix which is prepended to all php generated classes
|
2213
|
+
from this .proto. Default is empty.
|
2214
|
+
"""
|
2215
|
+
|
2216
|
+
php_namespace: "str" = betterproto2.field(41, betterproto2.TYPE_STRING)
|
2217
|
+
"""
|
2218
|
+
Use this option to change the namespace of php generated classes. Default
|
2219
|
+
is empty. When this option is empty, the package name will be used for
|
2220
|
+
determining the namespace.
|
2221
|
+
"""
|
2222
|
+
|
2223
|
+
php_metadata_namespace: "str" = betterproto2.field(44, betterproto2.TYPE_STRING)
|
2224
|
+
"""
|
2225
|
+
Use this option to change the namespace of php generated metadata classes.
|
2226
|
+
Default is empty. When this option is empty, the proto file name will be
|
2227
|
+
used for determining the namespace.
|
2228
|
+
"""
|
2229
|
+
|
2230
|
+
ruby_package: "str" = betterproto2.field(45, betterproto2.TYPE_STRING)
|
2231
|
+
"""
|
2232
|
+
Use this option to change the package of ruby generated classes. Default
|
2233
|
+
is empty. When this option is not set, the package name will be used for
|
2234
|
+
determining the ruby package.
|
2235
|
+
"""
|
2236
|
+
|
2237
|
+
features: "Optional[FeatureSet]" = betterproto2.field(50, betterproto2.TYPE_MESSAGE, optional=True)
|
2238
|
+
"""
|
2239
|
+
Any features defined in the specific edition.
|
2240
|
+
"""
|
2241
|
+
|
2242
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
2243
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
2244
|
+
)
|
2245
|
+
"""
|
2246
|
+
The parser stores options it doesn't recognize here.
|
2247
|
+
See the documentation for the "Options" section above.
|
2248
|
+
"""
|
2249
|
+
|
2250
|
+
def __post_init__(self) -> None:
|
2251
|
+
super().__post_init__()
|
2252
|
+
if self.is_set("java_generate_equals_and_hash"):
|
2253
|
+
warnings.warn("FileOptions.java_generate_equals_and_hash is deprecated", DeprecationWarning)
|
2254
|
+
|
2255
|
+
|
2256
|
+
default_message_pool.register_message("google.protobuf", "FileOptions", FileOptions)
|
2257
|
+
|
2258
|
+
|
2259
|
+
@dataclass(eq=False, repr=False)
|
2260
|
+
class FloatValue(betterproto2.Message):
|
2261
|
+
"""
|
2262
|
+
Wrapper message for `float`.
|
2263
|
+
|
2264
|
+
The JSON representation for `FloatValue` is JSON number.
|
2265
|
+
"""
|
2266
|
+
|
2267
|
+
value: "float" = betterproto2.field(1, betterproto2.TYPE_FLOAT)
|
2268
|
+
"""
|
2269
|
+
The float value.
|
2270
|
+
"""
|
2271
|
+
|
2272
|
+
|
2273
|
+
default_message_pool.register_message("google.protobuf", "FloatValue", FloatValue)
|
2274
|
+
|
2275
|
+
|
2276
|
+
@dataclass(eq=False, repr=False)
|
2277
|
+
class GeneratedCodeInfo(betterproto2.Message):
|
2278
|
+
"""
|
2279
|
+
Describes the relationship between generated code and its original source
|
2280
|
+
file. A GeneratedCodeInfo message is associated with only one generated
|
2281
|
+
source file, but may contain references to different source .proto files.
|
2282
|
+
"""
|
2283
|
+
|
2284
|
+
annotation: "List[GeneratedCodeInfoAnnotation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
|
2285
|
+
"""
|
2286
|
+
An Annotation connects some span of text in generated code to an element
|
2287
|
+
of its generating .proto file.
|
2288
|
+
"""
|
2289
|
+
|
2290
|
+
|
2291
|
+
default_message_pool.register_message("google.protobuf", "GeneratedCodeInfo", GeneratedCodeInfo)
|
2292
|
+
|
2293
|
+
|
2294
|
+
@dataclass(eq=False, repr=False)
|
2295
|
+
class GeneratedCodeInfoAnnotation(betterproto2.Message):
|
2296
|
+
path: "List[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
|
2297
|
+
"""
|
2298
|
+
Identifies the element in the original source .proto file. This field
|
2299
|
+
is formatted the same as SourceCodeInfo.Location.path.
|
2300
|
+
"""
|
2301
|
+
|
2302
|
+
source_file: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
2303
|
+
"""
|
2304
|
+
Identifies the filesystem path to the original source .proto.
|
2305
|
+
"""
|
2306
|
+
|
2307
|
+
begin: "int" = betterproto2.field(3, betterproto2.TYPE_INT32)
|
2308
|
+
"""
|
2309
|
+
Identifies the starting offset in bytes in the generated code
|
2310
|
+
that relates to the identified object.
|
2311
|
+
"""
|
2312
|
+
|
2313
|
+
end: "int" = betterproto2.field(4, betterproto2.TYPE_INT32)
|
2314
|
+
"""
|
2315
|
+
Identifies the ending offset in bytes in the generated code that
|
2316
|
+
relates to the identified object. The end offset should be one past
|
2317
|
+
the last relevant byte (so the length of the text = end - begin).
|
2318
|
+
"""
|
2319
|
+
|
2320
|
+
semantic: "GeneratedCodeInfoAnnotationSemantic" = betterproto2.field(
|
2321
|
+
5, betterproto2.TYPE_ENUM, default_factory=lambda: GeneratedCodeInfoAnnotationSemantic.try_value(0)
|
2322
|
+
)
|
2323
|
+
|
2324
|
+
|
2325
|
+
default_message_pool.register_message("google.protobuf", "GeneratedCodeInfo.Annotation", GeneratedCodeInfoAnnotation)
|
2326
|
+
|
2327
|
+
|
2328
|
+
@dataclass(eq=False, repr=False)
|
2329
|
+
class Int32Value(betterproto2.Message):
|
2330
|
+
"""
|
2331
|
+
Wrapper message for `int32`.
|
2332
|
+
|
2333
|
+
The JSON representation for `Int32Value` is JSON number.
|
2334
|
+
"""
|
2335
|
+
|
2336
|
+
value: "int" = betterproto2.field(1, betterproto2.TYPE_INT32)
|
2337
|
+
"""
|
2338
|
+
The int32 value.
|
2339
|
+
"""
|
2340
|
+
|
2341
|
+
|
2342
|
+
default_message_pool.register_message("google.protobuf", "Int32Value", Int32Value)
|
2343
|
+
|
2344
|
+
|
2345
|
+
@dataclass(eq=False, repr=False)
|
2346
|
+
class Int64Value(betterproto2.Message):
|
2347
|
+
"""
|
2348
|
+
Wrapper message for `int64`.
|
2349
|
+
|
2350
|
+
The JSON representation for `Int64Value` is JSON string.
|
2351
|
+
"""
|
2352
|
+
|
2353
|
+
value: "int" = betterproto2.field(1, betterproto2.TYPE_INT64)
|
2354
|
+
"""
|
2355
|
+
The int64 value.
|
2356
|
+
"""
|
2357
|
+
|
2358
|
+
|
2359
|
+
default_message_pool.register_message("google.protobuf", "Int64Value", Int64Value)
|
2360
|
+
|
2361
|
+
|
2362
|
+
@dataclass(eq=False, repr=False)
|
2363
|
+
class ListValue(betterproto2.Message):
|
2364
|
+
"""
|
2365
|
+
`ListValue` is a wrapper around a repeated field of values.
|
2366
|
+
|
2367
|
+
The JSON representation for `ListValue` is JSON array.
|
2368
|
+
"""
|
2369
|
+
|
2370
|
+
values: "List[Value]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
|
2371
|
+
"""
|
2372
|
+
Repeated field of dynamically typed values.
|
2373
|
+
"""
|
2374
|
+
|
2375
|
+
|
2376
|
+
default_message_pool.register_message("google.protobuf", "ListValue", ListValue)
|
2377
|
+
|
2378
|
+
|
2379
|
+
@dataclass(eq=False, repr=False)
|
2380
|
+
class MessageOptions(betterproto2.Message):
|
2381
|
+
message_set_wire_format: "bool" = betterproto2.field(1, betterproto2.TYPE_BOOL)
|
2382
|
+
"""
|
2383
|
+
Set true to use the old proto1 MessageSet wire format for extensions.
|
2384
|
+
This is provided for backwards-compatibility with the MessageSet wire
|
2385
|
+
format. You should not use this for any other reason: It's less
|
2386
|
+
efficient, has fewer features, and is more complicated.
|
2387
|
+
|
2388
|
+
The message must be defined exactly as follows:
|
2389
|
+
message Foo {
|
2390
|
+
option message_set_wire_format = true;
|
2391
|
+
extensions 4 to max;
|
2392
|
+
}
|
2393
|
+
Note that the message cannot have any defined fields; MessageSets only
|
2394
|
+
have extensions.
|
2395
|
+
|
2396
|
+
All extensions of your type must be singular messages; e.g. they cannot
|
2397
|
+
be int32s, enums, or repeated messages.
|
2398
|
+
|
2399
|
+
Because this is an option, the above two restrictions are not enforced by
|
2400
|
+
the protocol compiler.
|
2401
|
+
"""
|
2402
|
+
|
2403
|
+
no_standard_descriptor_accessor: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
|
2404
|
+
"""
|
2405
|
+
Disables the generation of the standard "descriptor()" accessor, which can
|
2406
|
+
conflict with a field of the same name. This is meant to make migration
|
2407
|
+
from proto1 easier; new code should avoid fields named "descriptor".
|
2408
|
+
"""
|
2409
|
+
|
2410
|
+
deprecated: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
|
2411
|
+
"""
|
2412
|
+
Is this message deprecated?
|
2413
|
+
Depending on the target platform, this can emit Deprecated annotations
|
2414
|
+
for the message, or it will be completely ignored; in the very least,
|
2415
|
+
this is a formalization for deprecating messages.
|
2416
|
+
"""
|
2417
|
+
|
2418
|
+
map_entry: "bool" = betterproto2.field(7, betterproto2.TYPE_BOOL)
|
2419
|
+
"""
|
2420
|
+
NOTE: Do not set the option in .proto files. Always use the maps syntax
|
2421
|
+
instead. The option should only be implicitly set by the proto compiler
|
2422
|
+
parser.
|
2423
|
+
|
2424
|
+
Whether the message is an automatically generated map entry type for the
|
2425
|
+
maps field.
|
2426
|
+
|
2427
|
+
For maps fields:
|
2428
|
+
map<KeyType, ValueType> map_field = 1;
|
2429
|
+
The parsed descriptor looks like:
|
2430
|
+
message MapFieldEntry {
|
2431
|
+
option map_entry = true;
|
2432
|
+
optional KeyType key = 1;
|
2433
|
+
optional ValueType value = 2;
|
2434
|
+
}
|
2435
|
+
repeated MapFieldEntry map_field = 1;
|
2436
|
+
|
2437
|
+
Implementations may choose not to generate the map_entry=true message, but
|
2438
|
+
use a native map in the target language to hold the keys and values.
|
2439
|
+
The reflection APIs in such implementations still need to work as
|
2440
|
+
if the field is a repeated message field.
|
2441
|
+
"""
|
2442
|
+
|
2443
|
+
deprecated_legacy_json_field_conflicts: "bool" = betterproto2.field(11, betterproto2.TYPE_BOOL)
|
2444
|
+
"""
|
2445
|
+
Enable the legacy handling of JSON field name conflicts. This lowercases
|
2446
|
+
and strips underscored from the fields before comparison in proto3 only.
|
2447
|
+
The new behavior takes `json_name` into account and applies to proto2 as
|
2448
|
+
well.
|
2449
|
+
|
2450
|
+
This should only be used as a temporary measure against broken builds due
|
2451
|
+
to the change in behavior for JSON field name conflicts.
|
2452
|
+
|
2453
|
+
TODO This is legacy behavior we plan to remove once downstream
|
2454
|
+
teams have had time to migrate.
|
2455
|
+
"""
|
2456
|
+
|
2457
|
+
features: "Optional[FeatureSet]" = betterproto2.field(12, betterproto2.TYPE_MESSAGE, optional=True)
|
2458
|
+
"""
|
2459
|
+
Any features defined in the specific edition.
|
2460
|
+
"""
|
2461
|
+
|
2462
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
2463
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
2464
|
+
)
|
2465
|
+
"""
|
2466
|
+
The parser stores options it doesn't recognize here. See above.
|
2467
|
+
"""
|
2468
|
+
|
2469
|
+
def __post_init__(self) -> None:
|
2470
|
+
super().__post_init__()
|
2471
|
+
if self.is_set("deprecated_legacy_json_field_conflicts"):
|
2472
|
+
warnings.warn("MessageOptions.deprecated_legacy_json_field_conflicts is deprecated", DeprecationWarning)
|
2473
|
+
|
2474
|
+
|
2475
|
+
default_message_pool.register_message("google.protobuf", "MessageOptions", MessageOptions)
|
2476
|
+
|
2477
|
+
|
2478
|
+
@dataclass(eq=False, repr=False)
|
2479
|
+
class Method(betterproto2.Message):
|
2480
|
+
"""
|
2481
|
+
Method represents a method of an API interface.
|
2482
|
+
"""
|
2483
|
+
|
2484
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2485
|
+
"""
|
2486
|
+
The simple name of this method.
|
2487
|
+
"""
|
2488
|
+
|
2489
|
+
request_type_url: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
2490
|
+
"""
|
2491
|
+
A URL of the input message type.
|
2492
|
+
"""
|
2493
|
+
|
2494
|
+
request_streaming: "bool" = betterproto2.field(3, betterproto2.TYPE_BOOL)
|
2495
|
+
"""
|
2496
|
+
If true, the request is streamed.
|
2497
|
+
"""
|
2498
|
+
|
2499
|
+
response_type_url: "str" = betterproto2.field(4, betterproto2.TYPE_STRING)
|
2500
|
+
"""
|
2501
|
+
The URL of the output message type.
|
2502
|
+
"""
|
2503
|
+
|
2504
|
+
response_streaming: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
|
2505
|
+
"""
|
2506
|
+
If true, the response is streamed.
|
2507
|
+
"""
|
2508
|
+
|
2509
|
+
options: "List[Option]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, repeated=True)
|
2510
|
+
"""
|
2511
|
+
Any metadata attached to the method.
|
2512
|
+
"""
|
2513
|
+
|
2514
|
+
syntax: "Syntax" = betterproto2.field(7, betterproto2.TYPE_ENUM, default_factory=lambda: Syntax.try_value(0))
|
2515
|
+
"""
|
2516
|
+
The source syntax of this method.
|
2517
|
+
"""
|
2518
|
+
|
2519
|
+
|
2520
|
+
default_message_pool.register_message("google.protobuf", "Method", Method)
|
2521
|
+
|
2522
|
+
|
2523
|
+
@dataclass(eq=False, repr=False)
|
2524
|
+
class MethodDescriptorProto(betterproto2.Message):
|
2525
|
+
"""
|
2526
|
+
Describes a method of a service.
|
2527
|
+
"""
|
2528
|
+
|
2529
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2530
|
+
|
2531
|
+
input_type: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
2532
|
+
"""
|
2533
|
+
Input and output type names. These are resolved in the same way as
|
2534
|
+
FieldDescriptorProto.type_name, but must refer to a message type.
|
2535
|
+
"""
|
2536
|
+
|
2537
|
+
output_type: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
|
2538
|
+
|
2539
|
+
options: "Optional[MethodOptions]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, optional=True)
|
2540
|
+
|
2541
|
+
client_streaming: "bool" = betterproto2.field(5, betterproto2.TYPE_BOOL)
|
2542
|
+
"""
|
2543
|
+
Identifies if client streams multiple client messages
|
2544
|
+
"""
|
2545
|
+
|
2546
|
+
server_streaming: "bool" = betterproto2.field(6, betterproto2.TYPE_BOOL)
|
2547
|
+
"""
|
2548
|
+
Identifies if server streams multiple server messages
|
2549
|
+
"""
|
2550
|
+
|
2551
|
+
|
2552
|
+
default_message_pool.register_message("google.protobuf", "MethodDescriptorProto", MethodDescriptorProto)
|
2553
|
+
|
2554
|
+
|
2555
|
+
@dataclass(eq=False, repr=False)
|
2556
|
+
class MethodOptions(betterproto2.Message):
|
2557
|
+
deprecated: "bool" = betterproto2.field(33, betterproto2.TYPE_BOOL)
|
2558
|
+
"""
|
2559
|
+
Note: Field numbers 1 through 32 are reserved for Google's internal RPC
|
2560
|
+
framework. We apologize for hoarding these numbers to ourselves, but
|
2561
|
+
we were already using them long before we decided to release Protocol
|
2562
|
+
Buffers.
|
2563
|
+
|
2564
|
+
Is this method deprecated?
|
2565
|
+
Depending on the target platform, this can emit Deprecated annotations
|
2566
|
+
for the method, or it will be completely ignored; in the very least,
|
2567
|
+
this is a formalization for deprecating methods.
|
2568
|
+
"""
|
2569
|
+
|
2570
|
+
idempotency_level: "MethodOptionsIdempotencyLevel" = betterproto2.field(
|
2571
|
+
34, betterproto2.TYPE_ENUM, default_factory=lambda: MethodOptionsIdempotencyLevel.try_value(0)
|
2572
|
+
)
|
2573
|
+
|
2574
|
+
features: "Optional[FeatureSet]" = betterproto2.field(35, betterproto2.TYPE_MESSAGE, optional=True)
|
2575
|
+
"""
|
2576
|
+
Any features defined in the specific edition.
|
2577
|
+
"""
|
2578
|
+
|
2579
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
2580
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
2581
|
+
)
|
2582
|
+
"""
|
2583
|
+
The parser stores options it doesn't recognize here. See above.
|
2584
|
+
"""
|
2585
|
+
|
2586
|
+
|
2587
|
+
default_message_pool.register_message("google.protobuf", "MethodOptions", MethodOptions)
|
2588
|
+
|
2589
|
+
|
2590
|
+
@dataclass(eq=False, repr=False)
|
2591
|
+
class Mixin(betterproto2.Message):
|
2592
|
+
"""
|
2593
|
+
Declares an API Interface to be included in this interface. The including
|
2594
|
+
interface must redeclare all the methods from the included interface, but
|
2595
|
+
documentation and options are inherited as follows:
|
2596
|
+
|
2597
|
+
- If after comment and whitespace stripping, the documentation
|
2598
|
+
string of the redeclared method is empty, it will be inherited
|
2599
|
+
from the original method.
|
2600
|
+
|
2601
|
+
- Each annotation belonging to the service config (http,
|
2602
|
+
visibility) which is not set in the redeclared method will be
|
2603
|
+
inherited.
|
2604
|
+
|
2605
|
+
- If an http annotation is inherited, the path pattern will be
|
2606
|
+
modified as follows. Any version prefix will be replaced by the
|
2607
|
+
version of the including interface plus the [root][] path if
|
2608
|
+
specified.
|
2609
|
+
|
2610
|
+
Example of a simple mixin:
|
2611
|
+
|
2612
|
+
package google.acl.v1;
|
2613
|
+
service AccessControl {
|
2614
|
+
// Get the underlying ACL object.
|
2615
|
+
rpc GetAcl(GetAclRequest) returns (Acl) {
|
2616
|
+
option (google.api.http).get = "/v1/{resource=**}:getAcl";
|
2617
|
+
}
|
2618
|
+
}
|
2619
|
+
|
2620
|
+
package google.storage.v2;
|
2621
|
+
service Storage {
|
2622
|
+
rpc GetAcl(GetAclRequest) returns (Acl);
|
2623
|
+
|
2624
|
+
// Get a data record.
|
2625
|
+
rpc GetData(GetDataRequest) returns (Data) {
|
2626
|
+
option (google.api.http).get = "/v2/{resource=**}";
|
2627
|
+
}
|
2628
|
+
}
|
2629
|
+
|
2630
|
+
Example of a mixin configuration:
|
2631
|
+
|
2632
|
+
apis:
|
2633
|
+
- name: google.storage.v2.Storage
|
2634
|
+
mixins:
|
2635
|
+
- name: google.acl.v1.AccessControl
|
2636
|
+
|
2637
|
+
The mixin construct implies that all methods in `AccessControl` are
|
2638
|
+
also declared with same name and request/response types in
|
2639
|
+
`Storage`. A documentation generator or annotation processor will
|
2640
|
+
see the effective `Storage.GetAcl` method after inherting
|
2641
|
+
documentation and annotations as follows:
|
2642
|
+
|
2643
|
+
service Storage {
|
2644
|
+
// Get the underlying ACL object.
|
2645
|
+
rpc GetAcl(GetAclRequest) returns (Acl) {
|
2646
|
+
option (google.api.http).get = "/v2/{resource=**}:getAcl";
|
2647
|
+
}
|
2648
|
+
...
|
2649
|
+
}
|
2650
|
+
|
2651
|
+
Note how the version in the path pattern changed from `v1` to `v2`.
|
2652
|
+
|
2653
|
+
If the `root` field in the mixin is specified, it should be a
|
2654
|
+
relative path under which inherited HTTP paths are placed. Example:
|
2655
|
+
|
2656
|
+
apis:
|
2657
|
+
- name: google.storage.v2.Storage
|
2658
|
+
mixins:
|
2659
|
+
- name: google.acl.v1.AccessControl
|
2660
|
+
root: acls
|
2661
|
+
|
2662
|
+
This implies the following inherited HTTP annotation:
|
2663
|
+
|
2664
|
+
service Storage {
|
2665
|
+
// Get the underlying ACL object.
|
2666
|
+
rpc GetAcl(GetAclRequest) returns (Acl) {
|
2667
|
+
option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
|
2668
|
+
}
|
2669
|
+
...
|
2670
|
+
}
|
2671
|
+
"""
|
2672
|
+
|
2673
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2674
|
+
"""
|
2675
|
+
The fully qualified name of the interface which is included.
|
2676
|
+
"""
|
2677
|
+
|
2678
|
+
root: "str" = betterproto2.field(2, betterproto2.TYPE_STRING)
|
2679
|
+
"""
|
2680
|
+
If non-empty specifies a path under which inherited HTTP paths
|
2681
|
+
are rooted.
|
2682
|
+
"""
|
2683
|
+
|
2684
|
+
|
2685
|
+
default_message_pool.register_message("google.protobuf", "Mixin", Mixin)
|
2686
|
+
|
2687
|
+
|
2688
|
+
@dataclass(eq=False, repr=False)
|
2689
|
+
class OneofDescriptorProto(betterproto2.Message):
|
2690
|
+
"""
|
2691
|
+
Describes a oneof.
|
2692
|
+
"""
|
2693
|
+
|
2694
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2695
|
+
|
2696
|
+
options: "Optional[OneofOptions]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
|
2697
|
+
|
2698
|
+
|
2699
|
+
default_message_pool.register_message("google.protobuf", "OneofDescriptorProto", OneofDescriptorProto)
|
2700
|
+
|
2701
|
+
|
2702
|
+
@dataclass(eq=False, repr=False)
|
2703
|
+
class OneofOptions(betterproto2.Message):
|
2704
|
+
features: "Optional[FeatureSet]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, optional=True)
|
2705
|
+
"""
|
2706
|
+
Any features defined in the specific edition.
|
2707
|
+
"""
|
2708
|
+
|
2709
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
2710
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
2711
|
+
)
|
2712
|
+
"""
|
2713
|
+
The parser stores options it doesn't recognize here. See above.
|
2714
|
+
"""
|
2715
|
+
|
2716
|
+
|
2717
|
+
default_message_pool.register_message("google.protobuf", "OneofOptions", OneofOptions)
|
2718
|
+
|
2719
|
+
|
2720
|
+
@dataclass(eq=False, repr=False)
|
2721
|
+
class Option(betterproto2.Message):
|
2722
|
+
"""
|
2723
|
+
A protocol buffer option, which can be attached to a message, field,
|
2724
|
+
enumeration, etc.
|
2725
|
+
"""
|
2726
|
+
|
2727
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2728
|
+
"""
|
2729
|
+
The option's name. For protobuf built-in options (options defined in
|
2730
|
+
descriptor.proto), this is the short name. For example, `"map_entry"`.
|
2731
|
+
For custom options, it should be the fully-qualified name. For example,
|
2732
|
+
`"google.api.http"`.
|
2733
|
+
"""
|
2734
|
+
|
2735
|
+
value: "Optional[Any]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, optional=True)
|
2736
|
+
"""
|
2737
|
+
The option's value packed in an Any message. If the value is a primitive,
|
2738
|
+
the corresponding wrapper type defined in google/protobuf/wrappers.proto
|
2739
|
+
should be used. If the value is an enum, it should be stored as an int32
|
2740
|
+
value using the google.protobuf.Int32Value type.
|
2741
|
+
"""
|
2742
|
+
|
2743
|
+
|
2744
|
+
default_message_pool.register_message("google.protobuf", "Option", Option)
|
2745
|
+
|
2746
|
+
|
2747
|
+
@dataclass(eq=False, repr=False)
|
2748
|
+
class ServiceDescriptorProto(betterproto2.Message):
|
2749
|
+
"""
|
2750
|
+
Describes a service.
|
2751
|
+
"""
|
2752
|
+
|
2753
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2754
|
+
|
2755
|
+
method: "List[MethodDescriptorProto]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
2756
|
+
|
2757
|
+
options: "Optional[ServiceOptions]" = betterproto2.field(3, betterproto2.TYPE_MESSAGE, optional=True)
|
2758
|
+
|
2759
|
+
|
2760
|
+
default_message_pool.register_message("google.protobuf", "ServiceDescriptorProto", ServiceDescriptorProto)
|
2761
|
+
|
2762
|
+
|
2763
|
+
@dataclass(eq=False, repr=False)
|
2764
|
+
class ServiceOptions(betterproto2.Message):
|
2765
|
+
features: "Optional[FeatureSet]" = betterproto2.field(34, betterproto2.TYPE_MESSAGE, optional=True)
|
2766
|
+
"""
|
2767
|
+
Any features defined in the specific edition.
|
2768
|
+
"""
|
2769
|
+
|
2770
|
+
deprecated: "bool" = betterproto2.field(33, betterproto2.TYPE_BOOL)
|
2771
|
+
"""
|
2772
|
+
Note: Field numbers 1 through 32 are reserved for Google's internal RPC
|
2773
|
+
framework. We apologize for hoarding these numbers to ourselves, but
|
2774
|
+
we were already using them long before we decided to release Protocol
|
2775
|
+
Buffers.
|
2776
|
+
|
2777
|
+
Is this service deprecated?
|
2778
|
+
Depending on the target platform, this can emit Deprecated annotations
|
2779
|
+
for the service, or it will be completely ignored; in the very least,
|
2780
|
+
this is a formalization for deprecating services.
|
2781
|
+
"""
|
2782
|
+
|
2783
|
+
uninterpreted_option: "List[UninterpretedOption]" = betterproto2.field(
|
2784
|
+
999, betterproto2.TYPE_MESSAGE, repeated=True
|
2785
|
+
)
|
2786
|
+
"""
|
2787
|
+
The parser stores options it doesn't recognize here. See above.
|
2788
|
+
"""
|
2789
|
+
|
2790
|
+
|
2791
|
+
default_message_pool.register_message("google.protobuf", "ServiceOptions", ServiceOptions)
|
2792
|
+
|
2793
|
+
|
2794
|
+
@dataclass(eq=False, repr=False)
|
2795
|
+
class SourceCodeInfo(betterproto2.Message):
|
2796
|
+
"""
|
2797
|
+
===================================================================
|
2798
|
+
Optional source code info
|
2799
|
+
|
2800
|
+
Encapsulates information about the original source file from which a
|
2801
|
+
FileDescriptorProto was generated.
|
2802
|
+
"""
|
2803
|
+
|
2804
|
+
location: "List[SourceCodeInfoLocation]" = betterproto2.field(1, betterproto2.TYPE_MESSAGE, repeated=True)
|
2805
|
+
"""
|
2806
|
+
A Location identifies a piece of source code in a .proto file which
|
2807
|
+
corresponds to a particular definition. This information is intended
|
2808
|
+
to be useful to IDEs, code indexers, documentation generators, and similar
|
2809
|
+
tools.
|
2810
|
+
|
2811
|
+
For example, say we have a file like:
|
2812
|
+
message Foo {
|
2813
|
+
optional string foo = 1;
|
2814
|
+
}
|
2815
|
+
Let's look at just the field definition:
|
2816
|
+
optional string foo = 1;
|
2817
|
+
^ ^^ ^^ ^ ^^^
|
2818
|
+
a bc de f ghi
|
2819
|
+
We have the following locations:
|
2820
|
+
span path represents
|
2821
|
+
[a,i) [ 4, 0, 2, 0 ] The whole field definition.
|
2822
|
+
[a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
|
2823
|
+
[c,d) [ 4, 0, 2, 0, 5 ] The type (string).
|
2824
|
+
[e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
|
2825
|
+
[g,h) [ 4, 0, 2, 0, 3 ] The number (1).
|
2826
|
+
|
2827
|
+
Notes:
|
2828
|
+
- A location may refer to a repeated field itself (i.e. not to any
|
2829
|
+
particular index within it). This is used whenever a set of elements are
|
2830
|
+
logically enclosed in a single code segment. For example, an entire
|
2831
|
+
extend block (possibly containing multiple extension definitions) will
|
2832
|
+
have an outer location whose path refers to the "extensions" repeated
|
2833
|
+
field without an index.
|
2834
|
+
- Multiple locations may have the same path. This happens when a single
|
2835
|
+
logical declaration is spread out across multiple places. The most
|
2836
|
+
obvious example is the "extend" block again -- there may be multiple
|
2837
|
+
extend blocks in the same scope, each of which will have the same path.
|
2838
|
+
- A location's span is not always a subset of its parent's span. For
|
2839
|
+
example, the "extendee" of an extension declaration appears at the
|
2840
|
+
beginning of the "extend" block and is shared by all extensions within
|
2841
|
+
the block.
|
2842
|
+
- Just because a location's span is a subset of some other location's span
|
2843
|
+
does not mean that it is a descendant. For example, a "group" defines
|
2844
|
+
both a type and a field in a single declaration. Thus, the locations
|
2845
|
+
corresponding to the type and field and their components will overlap.
|
2846
|
+
- Code which tries to interpret locations should probably be designed to
|
2847
|
+
ignore those that it doesn't understand, as more types of locations could
|
2848
|
+
be recorded in the future.
|
2849
|
+
"""
|
2850
|
+
|
2851
|
+
|
2852
|
+
default_message_pool.register_message("google.protobuf", "SourceCodeInfo", SourceCodeInfo)
|
2853
|
+
|
2854
|
+
|
2855
|
+
@dataclass(eq=False, repr=False)
|
2856
|
+
class SourceCodeInfoLocation(betterproto2.Message):
|
2857
|
+
path: "List[int]" = betterproto2.field(1, betterproto2.TYPE_INT32, repeated=True)
|
2858
|
+
"""
|
2859
|
+
Identifies which part of the FileDescriptorProto was defined at this
|
2860
|
+
location.
|
2861
|
+
|
2862
|
+
Each element is a field number or an index. They form a path from
|
2863
|
+
the root FileDescriptorProto to the place where the definition occurs.
|
2864
|
+
For example, this path:
|
2865
|
+
[ 4, 3, 2, 7, 1 ]
|
2866
|
+
refers to:
|
2867
|
+
file.message_type(3) // 4, 3
|
2868
|
+
.field(7) // 2, 7
|
2869
|
+
.name() // 1
|
2870
|
+
This is because FileDescriptorProto.message_type has field number 4:
|
2871
|
+
repeated DescriptorProto message_type = 4;
|
2872
|
+
and DescriptorProto.field has field number 2:
|
2873
|
+
repeated FieldDescriptorProto field = 2;
|
2874
|
+
and FieldDescriptorProto.name has field number 1:
|
2875
|
+
optional string name = 1;
|
2876
|
+
|
2877
|
+
Thus, the above path gives the location of a field name. If we removed
|
2878
|
+
the last element:
|
2879
|
+
[ 4, 3, 2, 7 ]
|
2880
|
+
this path refers to the whole field declaration (from the beginning
|
2881
|
+
of the label to the terminating semicolon).
|
2882
|
+
"""
|
2883
|
+
|
2884
|
+
span: "List[int]" = betterproto2.field(2, betterproto2.TYPE_INT32, repeated=True)
|
2885
|
+
"""
|
2886
|
+
Always has exactly three or four elements: start line, start column,
|
2887
|
+
end line (optional, otherwise assumed same as start line), end column.
|
2888
|
+
These are packed into a single field for efficiency. Note that line
|
2889
|
+
and column numbers are zero-based -- typically you will want to add
|
2890
|
+
1 to each before displaying to a user.
|
2891
|
+
"""
|
2892
|
+
|
2893
|
+
leading_comments: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
|
2894
|
+
"""
|
2895
|
+
If this SourceCodeInfo represents a complete declaration, these are any
|
2896
|
+
comments appearing before and after the declaration which appear to be
|
2897
|
+
attached to the declaration.
|
2898
|
+
|
2899
|
+
A series of line comments appearing on consecutive lines, with no other
|
2900
|
+
tokens appearing on those lines, will be treated as a single comment.
|
2901
|
+
|
2902
|
+
leading_detached_comments will keep paragraphs of comments that appear
|
2903
|
+
before (but not connected to) the current element. Each paragraph,
|
2904
|
+
separated by empty lines, will be one comment element in the repeated
|
2905
|
+
field.
|
2906
|
+
|
2907
|
+
Only the comment content is provided; comment markers (e.g. //) are
|
2908
|
+
stripped out. For block comments, leading whitespace and an asterisk
|
2909
|
+
will be stripped from the beginning of each line other than the first.
|
2910
|
+
Newlines are included in the output.
|
2911
|
+
|
2912
|
+
Examples:
|
2913
|
+
|
2914
|
+
optional int32 foo = 1; // Comment attached to foo.
|
2915
|
+
// Comment attached to bar.
|
2916
|
+
optional int32 bar = 2;
|
2917
|
+
|
2918
|
+
optional string baz = 3;
|
2919
|
+
// Comment attached to baz.
|
2920
|
+
// Another line attached to baz.
|
2921
|
+
|
2922
|
+
// Comment attached to moo.
|
2923
|
+
//
|
2924
|
+
// Another line attached to moo.
|
2925
|
+
optional double moo = 4;
|
2926
|
+
|
2927
|
+
// Detached comment for corge. This is not leading or trailing comments
|
2928
|
+
// to moo or corge because there are blank lines separating it from
|
2929
|
+
// both.
|
2930
|
+
|
2931
|
+
// Detached comment for corge paragraph 2.
|
2932
|
+
|
2933
|
+
optional string corge = 5;
|
2934
|
+
/* Block comment attached
|
2935
|
+
* to corge. Leading asterisks
|
2936
|
+
* will be removed. */
|
2937
|
+
/* Block comment attached to
|
2938
|
+
* grault. */
|
2939
|
+
optional int32 grault = 6;
|
2940
|
+
|
2941
|
+
// ignored detached comments.
|
2942
|
+
"""
|
2943
|
+
|
2944
|
+
trailing_comments: "str" = betterproto2.field(4, betterproto2.TYPE_STRING)
|
2945
|
+
|
2946
|
+
leading_detached_comments: "List[str]" = betterproto2.field(6, betterproto2.TYPE_STRING, repeated=True)
|
2947
|
+
|
2948
|
+
|
2949
|
+
default_message_pool.register_message("google.protobuf", "SourceCodeInfo.Location", SourceCodeInfoLocation)
|
2950
|
+
|
2951
|
+
|
2952
|
+
@dataclass(eq=False, repr=False)
|
2953
|
+
class SourceContext(betterproto2.Message):
|
2954
|
+
"""
|
2955
|
+
`SourceContext` represents information about the source of a
|
2956
|
+
protobuf element, like the file in which it is defined.
|
2957
|
+
"""
|
2958
|
+
|
2959
|
+
file_name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2960
|
+
"""
|
2961
|
+
The path-qualified name of the .proto file that contained the associated
|
2962
|
+
protobuf element. For example: `"google/protobuf/source_context.proto"`.
|
2963
|
+
"""
|
2964
|
+
|
2965
|
+
|
2966
|
+
default_message_pool.register_message("google.protobuf", "SourceContext", SourceContext)
|
2967
|
+
|
2968
|
+
|
2969
|
+
@dataclass(eq=False, repr=False)
|
2970
|
+
class StringValue(betterproto2.Message):
|
2971
|
+
"""
|
2972
|
+
Wrapper message for `string`.
|
2973
|
+
|
2974
|
+
The JSON representation for `StringValue` is JSON string.
|
2975
|
+
"""
|
2976
|
+
|
2977
|
+
value: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
2978
|
+
"""
|
2979
|
+
The string value.
|
2980
|
+
"""
|
2981
|
+
|
2982
|
+
|
2983
|
+
default_message_pool.register_message("google.protobuf", "StringValue", StringValue)
|
2984
|
+
|
2985
|
+
|
2986
|
+
@dataclass(eq=False, repr=False)
|
2987
|
+
class Struct(betterproto2.Message):
|
2988
|
+
"""
|
2989
|
+
`Struct` represents a structured data value, consisting of fields
|
2990
|
+
which map to dynamically typed values. In some languages, `Struct`
|
2991
|
+
might be supported by a native representation. For example, in
|
2992
|
+
scripting languages like JS a struct is represented as an
|
2993
|
+
object. The details of that representation are described together
|
2994
|
+
with the proto support for the language.
|
2995
|
+
|
2996
|
+
The JSON representation for `Struct` is JSON object.
|
2997
|
+
"""
|
2998
|
+
|
2999
|
+
fields: "Dict[str, Value]" = betterproto2.field(
|
3000
|
+
1, betterproto2.TYPE_MAP, map_types=(betterproto2.TYPE_STRING, betterproto2.TYPE_MESSAGE)
|
3001
|
+
)
|
3002
|
+
"""
|
3003
|
+
Unordered map of dynamically typed values.
|
3004
|
+
"""
|
3005
|
+
|
3006
|
+
|
3007
|
+
default_message_pool.register_message("google.protobuf", "Struct", Struct)
|
3008
|
+
|
3009
|
+
|
3010
|
+
@dataclass(eq=False, repr=False)
|
3011
|
+
class Timestamp(betterproto2.Message):
|
3012
|
+
"""
|
3013
|
+
A Timestamp represents a point in time independent of any time zone or local
|
3014
|
+
calendar, encoded as a count of seconds and fractions of seconds at
|
3015
|
+
nanosecond resolution. The count is relative to an epoch at UTC midnight on
|
3016
|
+
January 1, 1970, in the proleptic Gregorian calendar which extends the
|
3017
|
+
Gregorian calendar backwards to year one.
|
3018
|
+
|
3019
|
+
All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
|
3020
|
+
second table is needed for interpretation, using a [24-hour linear
|
3021
|
+
smear](https://developers.google.com/time/smear).
|
3022
|
+
|
3023
|
+
The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
|
3024
|
+
restricting to that range, we ensure that we can convert to and from [RFC
|
3025
|
+
3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
|
3026
|
+
|
3027
|
+
# Examples
|
3028
|
+
|
3029
|
+
Example 1: Compute Timestamp from POSIX `time()`.
|
3030
|
+
|
3031
|
+
Timestamp timestamp;
|
3032
|
+
timestamp.set_seconds(time(NULL));
|
3033
|
+
timestamp.set_nanos(0);
|
3034
|
+
|
3035
|
+
Example 2: Compute Timestamp from POSIX `gettimeofday()`.
|
3036
|
+
|
3037
|
+
struct timeval tv;
|
3038
|
+
gettimeofday(&tv, NULL);
|
3039
|
+
|
3040
|
+
Timestamp timestamp;
|
3041
|
+
timestamp.set_seconds(tv.tv_sec);
|
3042
|
+
timestamp.set_nanos(tv.tv_usec * 1000);
|
3043
|
+
|
3044
|
+
Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
|
3045
|
+
|
3046
|
+
FILETIME ft;
|
3047
|
+
GetSystemTimeAsFileTime(&ft);
|
3048
|
+
UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
|
3049
|
+
|
3050
|
+
// A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
|
3051
|
+
// is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
|
3052
|
+
Timestamp timestamp;
|
3053
|
+
timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
|
3054
|
+
timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
|
3055
|
+
|
3056
|
+
Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
|
3057
|
+
|
3058
|
+
long millis = System.currentTimeMillis();
|
3059
|
+
|
3060
|
+
Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
|
3061
|
+
.setNanos((int) ((millis % 1000) * 1000000)).build();
|
3062
|
+
|
3063
|
+
Example 5: Compute Timestamp from Java `Instant.now()`.
|
3064
|
+
|
3065
|
+
Instant now = Instant.now();
|
3066
|
+
|
3067
|
+
Timestamp timestamp =
|
3068
|
+
Timestamp.newBuilder().setSeconds(now.getEpochSecond())
|
3069
|
+
.setNanos(now.getNano()).build();
|
3070
|
+
|
3071
|
+
Example 6: Compute Timestamp from current time in Python.
|
3072
|
+
|
3073
|
+
timestamp = Timestamp()
|
3074
|
+
timestamp.GetCurrentTime()
|
3075
|
+
|
3076
|
+
# JSON Mapping
|
3077
|
+
|
3078
|
+
In JSON format, the Timestamp type is encoded as a string in the
|
3079
|
+
[RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
|
3080
|
+
format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
|
3081
|
+
where {year} is always expressed using four digits while {month}, {day},
|
3082
|
+
{hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
|
3083
|
+
seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
|
3084
|
+
are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
|
3085
|
+
is required. A proto3 JSON serializer should always use UTC (as indicated by
|
3086
|
+
"Z") when printing the Timestamp type and a proto3 JSON parser should be
|
3087
|
+
able to accept both UTC and other timezones (as indicated by an offset).
|
3088
|
+
|
3089
|
+
For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
|
3090
|
+
01:30 UTC on January 15, 2017.
|
3091
|
+
|
3092
|
+
In JavaScript, one can convert a Date object to this format using the
|
3093
|
+
standard
|
3094
|
+
[toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
|
3095
|
+
method. In Python, a standard `datetime.datetime` object can be converted
|
3096
|
+
to this format using
|
3097
|
+
[`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
|
3098
|
+
the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
|
3099
|
+
the Joda Time's [`ISODateTimeFormat.dateTime()`](
|
3100
|
+
http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
|
3101
|
+
) to obtain a formatter capable of generating timestamps in this format.
|
3102
|
+
"""
|
3103
|
+
|
3104
|
+
seconds: "int" = betterproto2.field(1, betterproto2.TYPE_INT64)
|
3105
|
+
"""
|
3106
|
+
Represents seconds of UTC time since Unix epoch
|
3107
|
+
1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
3108
|
+
9999-12-31T23:59:59Z inclusive.
|
3109
|
+
"""
|
3110
|
+
|
3111
|
+
nanos: "int" = betterproto2.field(2, betterproto2.TYPE_INT32)
|
3112
|
+
"""
|
3113
|
+
Non-negative fractions of a second at nanosecond resolution. Negative
|
3114
|
+
second values with fractions must still have non-negative nanos values
|
3115
|
+
that count forward in time. Must be from 0 to 999,999,999
|
3116
|
+
inclusive.
|
3117
|
+
"""
|
3118
|
+
|
3119
|
+
@classmethod
|
3120
|
+
def from_datetime(cls, dt: datetime.datetime) -> "Timestamp":
|
3121
|
+
# manual epoch offset calulation to avoid rounding errors,
|
3122
|
+
# to support negative timestamps (before 1970) and skirt
|
3123
|
+
# around datetime bugs (apparently 0 isn't a year in [0, 9999]??)
|
3124
|
+
offset = dt - datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
|
3125
|
+
# below is the same as timedelta.total_seconds() but without dividing by 1e6
|
3126
|
+
# so we end up with microseconds as integers instead of seconds as float
|
3127
|
+
offset_us = (offset.days * 24 * 60 * 60 + offset.seconds) * 10**6 + offset.microseconds
|
3128
|
+
seconds, us = divmod(offset_us, 10**6)
|
3129
|
+
return cls(seconds, us * 1000)
|
3130
|
+
|
3131
|
+
def to_datetime(self) -> datetime.datetime:
|
3132
|
+
# datetime.fromtimestamp() expects a timestamp in seconds, not microseconds
|
3133
|
+
# if we pass it as a floating point number, we will run into rounding errors
|
3134
|
+
# see also #407
|
3135
|
+
offset = datetime.timedelta(seconds=self.seconds, microseconds=self.nanos // 1000)
|
3136
|
+
return datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) + offset
|
3137
|
+
|
3138
|
+
@staticmethod
|
3139
|
+
def timestamp_to_json(dt: datetime.datetime) -> str:
|
3140
|
+
nanos = dt.microsecond * 1e3
|
3141
|
+
if dt.tzinfo is not None:
|
3142
|
+
# change timezone aware datetime objects to utc
|
3143
|
+
dt = dt.astimezone(datetime.timezone.utc)
|
3144
|
+
copy = dt.replace(microsecond=0, tzinfo=None)
|
3145
|
+
result = copy.isoformat()
|
3146
|
+
if (nanos % 1e9) == 0:
|
3147
|
+
# If there are 0 fractional digits, the fractional
|
3148
|
+
# point '.' should be omitted when serializing.
|
3149
|
+
return f"{result}Z"
|
3150
|
+
if (nanos % 1e6) == 0:
|
3151
|
+
# Serialize 3 fractional digits.
|
3152
|
+
return f"{result}.{int(nanos // 1e6) :03d}Z"
|
3153
|
+
if (nanos % 1e3) == 0:
|
3154
|
+
# Serialize 6 fractional digits.
|
3155
|
+
return f"{result}.{int(nanos // 1e3) :06d}Z"
|
3156
|
+
# Serialize 9 fractional digits.
|
3157
|
+
return f"{result}.{nanos:09d}"
|
3158
|
+
|
3159
|
+
|
3160
|
+
default_message_pool.register_message("google.protobuf", "Timestamp", Timestamp)
|
3161
|
+
|
3162
|
+
|
3163
|
+
@dataclass(eq=False, repr=False)
|
3164
|
+
class Type(betterproto2.Message):
|
3165
|
+
"""
|
3166
|
+
A protocol buffer message type.
|
3167
|
+
"""
|
3168
|
+
|
3169
|
+
name: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
3170
|
+
"""
|
3171
|
+
The fully qualified message name.
|
3172
|
+
"""
|
3173
|
+
|
3174
|
+
fields: "List[Field]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
3175
|
+
"""
|
3176
|
+
The list of fields.
|
3177
|
+
"""
|
3178
|
+
|
3179
|
+
oneofs: "List[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, repeated=True)
|
3180
|
+
"""
|
3181
|
+
The list of types appearing in `oneof` definitions in this type.
|
3182
|
+
"""
|
3183
|
+
|
3184
|
+
options: "List[Option]" = betterproto2.field(4, betterproto2.TYPE_MESSAGE, repeated=True)
|
3185
|
+
"""
|
3186
|
+
The protocol buffer options.
|
3187
|
+
"""
|
3188
|
+
|
3189
|
+
source_context: "Optional[SourceContext]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True)
|
3190
|
+
"""
|
3191
|
+
The source context.
|
3192
|
+
"""
|
3193
|
+
|
3194
|
+
syntax: "Syntax" = betterproto2.field(6, betterproto2.TYPE_ENUM, default_factory=lambda: Syntax.try_value(0))
|
3195
|
+
"""
|
3196
|
+
The source syntax.
|
3197
|
+
"""
|
3198
|
+
|
3199
|
+
edition: "str" = betterproto2.field(7, betterproto2.TYPE_STRING)
|
3200
|
+
"""
|
3201
|
+
The source edition string, only valid when syntax is SYNTAX_EDITIONS.
|
3202
|
+
"""
|
3203
|
+
|
3204
|
+
|
3205
|
+
default_message_pool.register_message("google.protobuf", "Type", Type)
|
3206
|
+
|
3207
|
+
|
3208
|
+
@dataclass(eq=False, repr=False)
|
3209
|
+
class UInt32Value(betterproto2.Message):
|
3210
|
+
"""
|
3211
|
+
Wrapper message for `uint32`.
|
3212
|
+
|
3213
|
+
The JSON representation for `UInt32Value` is JSON number.
|
3214
|
+
"""
|
3215
|
+
|
3216
|
+
value: "int" = betterproto2.field(1, betterproto2.TYPE_UINT32)
|
3217
|
+
"""
|
3218
|
+
The uint32 value.
|
3219
|
+
"""
|
3220
|
+
|
3221
|
+
|
3222
|
+
default_message_pool.register_message("google.protobuf", "UInt32Value", UInt32Value)
|
3223
|
+
|
3224
|
+
|
3225
|
+
@dataclass(eq=False, repr=False)
|
3226
|
+
class UInt64Value(betterproto2.Message):
|
3227
|
+
"""
|
3228
|
+
Wrapper message for `uint64`.
|
3229
|
+
|
3230
|
+
The JSON representation for `UInt64Value` is JSON string.
|
3231
|
+
"""
|
3232
|
+
|
3233
|
+
value: "int" = betterproto2.field(1, betterproto2.TYPE_UINT64)
|
3234
|
+
"""
|
3235
|
+
The uint64 value.
|
3236
|
+
"""
|
3237
|
+
|
3238
|
+
|
3239
|
+
default_message_pool.register_message("google.protobuf", "UInt64Value", UInt64Value)
|
3240
|
+
|
3241
|
+
|
3242
|
+
@dataclass(eq=False, repr=False)
|
3243
|
+
class UninterpretedOption(betterproto2.Message):
|
3244
|
+
"""
|
3245
|
+
A message representing a option the parser does not recognize. This only
|
3246
|
+
appears in options protos created by the compiler::Parser class.
|
3247
|
+
DescriptorPool resolves these when building Descriptor objects. Therefore,
|
3248
|
+
options protos in descriptor objects (e.g. returned by Descriptor::options(),
|
3249
|
+
or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
|
3250
|
+
in them.
|
3251
|
+
"""
|
3252
|
+
|
3253
|
+
name: "List[UninterpretedOptionNamePart]" = betterproto2.field(2, betterproto2.TYPE_MESSAGE, repeated=True)
|
3254
|
+
|
3255
|
+
identifier_value: "str" = betterproto2.field(3, betterproto2.TYPE_STRING)
|
3256
|
+
"""
|
3257
|
+
The value of the uninterpreted option, in whatever type the tokenizer
|
3258
|
+
identified it as during parsing. Exactly one of these should be set.
|
3259
|
+
"""
|
3260
|
+
|
3261
|
+
positive_int_value: "int" = betterproto2.field(4, betterproto2.TYPE_UINT64)
|
3262
|
+
|
3263
|
+
negative_int_value: "int" = betterproto2.field(5, betterproto2.TYPE_INT64)
|
3264
|
+
|
3265
|
+
double_value: "float" = betterproto2.field(6, betterproto2.TYPE_DOUBLE)
|
3266
|
+
|
3267
|
+
string_value: "bytes" = betterproto2.field(7, betterproto2.TYPE_BYTES)
|
3268
|
+
|
3269
|
+
aggregate_value: "str" = betterproto2.field(8, betterproto2.TYPE_STRING)
|
3270
|
+
|
3271
|
+
|
3272
|
+
default_message_pool.register_message("google.protobuf", "UninterpretedOption", UninterpretedOption)
|
3273
|
+
|
3274
|
+
|
3275
|
+
@dataclass(eq=False, repr=False)
|
3276
|
+
class UninterpretedOptionNamePart(betterproto2.Message):
|
3277
|
+
"""
|
3278
|
+
The name of the uninterpreted option. Each string represents a segment in
|
3279
|
+
a dot-separated name. is_extension is true iff a segment represents an
|
3280
|
+
extension (denoted with parentheses in options specs in .proto files).
|
3281
|
+
E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
|
3282
|
+
"foo.(bar.baz).moo".
|
3283
|
+
"""
|
3284
|
+
|
3285
|
+
name_part: "str" = betterproto2.field(1, betterproto2.TYPE_STRING)
|
3286
|
+
|
3287
|
+
is_extension: "bool" = betterproto2.field(2, betterproto2.TYPE_BOOL)
|
3288
|
+
|
3289
|
+
|
3290
|
+
default_message_pool.register_message("google.protobuf", "UninterpretedOption.NamePart", UninterpretedOptionNamePart)
|
3291
|
+
|
3292
|
+
|
3293
|
+
@dataclass(eq=False, repr=False)
|
3294
|
+
class Value(betterproto2.Message):
|
3295
|
+
"""
|
3296
|
+
`Value` represents a dynamically typed value which can be either
|
3297
|
+
null, a number, a string, a boolean, a recursive struct value, or a
|
3298
|
+
list of values. A producer of value is expected to set one of these
|
3299
|
+
variants. Absence of any variant indicates an error.
|
3300
|
+
|
3301
|
+
The JSON representation for `Value` is JSON value.
|
3302
|
+
|
3303
|
+
Oneofs:
|
3304
|
+
- kind: The kind of value.
|
3305
|
+
"""
|
3306
|
+
|
3307
|
+
null_value: "Optional[NullValue]" = betterproto2.field(1, betterproto2.TYPE_ENUM, optional=True, group="kind")
|
3308
|
+
"""
|
3309
|
+
Represents a null value.
|
3310
|
+
"""
|
3311
|
+
|
3312
|
+
number_value: "Optional[float]" = betterproto2.field(2, betterproto2.TYPE_DOUBLE, optional=True, group="kind")
|
3313
|
+
"""
|
3314
|
+
Represents a double value.
|
3315
|
+
"""
|
3316
|
+
|
3317
|
+
string_value: "Optional[str]" = betterproto2.field(3, betterproto2.TYPE_STRING, optional=True, group="kind")
|
3318
|
+
"""
|
3319
|
+
Represents a string value.
|
3320
|
+
"""
|
3321
|
+
|
3322
|
+
bool_value: "Optional[bool]" = betterproto2.field(4, betterproto2.TYPE_BOOL, optional=True, group="kind")
|
3323
|
+
"""
|
3324
|
+
Represents a boolean value.
|
3325
|
+
"""
|
3326
|
+
|
3327
|
+
struct_value: "Optional[Struct]" = betterproto2.field(5, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
|
3328
|
+
"""
|
3329
|
+
Represents a structured value.
|
3330
|
+
"""
|
3331
|
+
|
3332
|
+
list_value: "Optional[ListValue]" = betterproto2.field(6, betterproto2.TYPE_MESSAGE, optional=True, group="kind")
|
3333
|
+
"""
|
3334
|
+
Represents a repeated `Value`.
|
3335
|
+
"""
|
3336
|
+
|
3337
|
+
|
3338
|
+
default_message_pool.register_message("google.protobuf", "Value", Value)
|