betterproto2-compiler 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2520 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # sources: google/protobuf/any.proto, google/protobuf/api.proto, google/protobuf/descriptor.proto,
3
- # google/protobuf/duration.proto, google/protobuf/empty.proto, google/protobuf/field_mask.proto,
4
- # google/protobuf/source_context.proto, google/protobuf/struct.proto, google/protobuf/timestamp.proto,
5
- # google/protobuf/type.proto, google/protobuf/wrappers.proto
6
- # plugin: python-betterproto2
7
- # This file has been @generated
8
-
9
- __all__ = (
10
- "Syntax",
11
- "FieldKind",
12
- "FieldCardinality",
13
- "FieldDescriptorProtoType",
14
- "FieldDescriptorProtoLabel",
15
- "FileOptionsOptimizeMode",
16
- "FieldOptionsCType",
17
- "FieldOptionsJsType",
18
- "MethodOptionsIdempotencyLevel",
19
- "NullValue",
20
- "Any",
21
- "SourceContext",
22
- "Type",
23
- "Field",
24
- "Enum",
25
- "EnumValue",
26
- "Option",
27
- "Api",
28
- "Method",
29
- "Mixin",
30
- "FileDescriptorSet",
31
- "FileDescriptorProto",
32
- "DescriptorProto",
33
- "DescriptorProtoExtensionRange",
34
- "DescriptorProtoReservedRange",
35
- "ExtensionRangeOptions",
36
- "FieldDescriptorProto",
37
- "OneofDescriptorProto",
38
- "EnumDescriptorProto",
39
- "EnumDescriptorProtoEnumReservedRange",
40
- "EnumValueDescriptorProto",
41
- "ServiceDescriptorProto",
42
- "MethodDescriptorProto",
43
- "FileOptions",
44
- "MessageOptions",
45
- "FieldOptions",
46
- "OneofOptions",
47
- "EnumOptions",
48
- "EnumValueOptions",
49
- "ServiceOptions",
50
- "MethodOptions",
51
- "UninterpretedOption",
52
- "UninterpretedOptionNamePart",
53
- "SourceCodeInfo",
54
- "SourceCodeInfoLocation",
55
- "GeneratedCodeInfo",
56
- "GeneratedCodeInfoAnnotation",
57
- "Duration",
58
- "Empty",
59
- "FieldMask",
60
- "Struct",
61
- "Value",
62
- "ListValue",
63
- "Timestamp",
64
- "DoubleValue",
65
- "FloatValue",
66
- "Int64Value",
67
- "UInt64Value",
68
- "Int32Value",
69
- "UInt32Value",
70
- "BoolValue",
71
- "StringValue",
72
- "BytesValue",
73
- )
74
-
75
- import warnings
76
- from dataclasses import dataclass
77
- from typing import (
78
- Dict,
79
- List,
80
- Mapping,
81
- )
82
-
83
- import betterproto2
84
- from betterproto2.utils import hybridmethod
85
- from typing_extensions import Self
86
-
87
-
88
- class Syntax(betterproto2.Enum):
89
- """The syntax in which a protocol buffer element is defined."""
90
-
91
- PROTO2 = 0
92
- """Syntax `proto2`."""
93
-
94
- PROTO3 = 1
95
- """Syntax `proto3`."""
96
-
97
-
98
- class FieldKind(betterproto2.Enum):
99
- """Basic field types."""
100
-
101
- TYPE_UNKNOWN = 0
102
- """Field type unknown."""
103
-
104
- TYPE_DOUBLE = 1
105
- """Field type double."""
106
-
107
- TYPE_FLOAT = 2
108
- """Field type float."""
109
-
110
- TYPE_INT64 = 3
111
- """Field type int64."""
112
-
113
- TYPE_UINT64 = 4
114
- """Field type uint64."""
115
-
116
- TYPE_INT32 = 5
117
- """Field type int32."""
118
-
119
- TYPE_FIXED64 = 6
120
- """Field type fixed64."""
121
-
122
- TYPE_FIXED32 = 7
123
- """Field type fixed32."""
124
-
125
- TYPE_BOOL = 8
126
- """Field type bool."""
127
-
128
- TYPE_STRING = 9
129
- """Field type string."""
130
-
131
- TYPE_GROUP = 10
132
- """Field type group. Proto2 syntax only, and deprecated."""
133
-
134
- TYPE_MESSAGE = 11
135
- """Field type message."""
136
-
137
- TYPE_BYTES = 12
138
- """Field type bytes."""
139
-
140
- TYPE_UINT32 = 13
141
- """Field type uint32."""
142
-
143
- TYPE_ENUM = 14
144
- """Field type enum."""
145
-
146
- TYPE_SFIXED32 = 15
147
- """Field type sfixed32."""
148
-
149
- TYPE_SFIXED64 = 16
150
- """Field type sfixed64."""
151
-
152
- TYPE_SINT32 = 17
153
- """Field type sint32."""
154
-
155
- TYPE_SINT64 = 18
156
- """Field type sint64."""
157
-
158
-
159
- class FieldCardinality(betterproto2.Enum):
160
- """Whether a field is optional, required, or repeated."""
161
-
162
- CARDINALITY_UNKNOWN = 0
163
- """For fields with unknown cardinality."""
164
-
165
- CARDINALITY_OPTIONAL = 1
166
- """For optional fields."""
167
-
168
- CARDINALITY_REQUIRED = 2
169
- """For required fields. Proto2 syntax only."""
170
-
171
- CARDINALITY_REPEATED = 3
172
- """For repeated fields."""
173
-
174
-
175
- class FieldDescriptorProtoType(betterproto2.Enum):
176
- """ """
177
-
178
- TYPE_DOUBLE = 1
179
- """
180
- 0 is reserved for errors.
181
- Order is weird for historical reasons.
182
- """
183
-
184
- TYPE_FLOAT = 2
185
- """
186
-
187
- """
188
-
189
- TYPE_INT64 = 3
190
- """
191
- Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
192
- negative values are likely.
193
- """
194
-
195
- TYPE_UINT64 = 4
196
- """
197
-
198
- """
199
-
200
- TYPE_INT32 = 5
201
- """
202
- Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
203
- negative values are likely.
204
- """
205
-
206
- TYPE_FIXED64 = 6
207
- """
208
-
209
- """
210
-
211
- TYPE_FIXED32 = 7
212
- """
213
-
214
- """
215
-
216
- TYPE_BOOL = 8
217
- """
218
-
219
- """
220
-
221
- TYPE_STRING = 9
222
- """
223
-
224
- """
225
-
226
- TYPE_GROUP = 10
227
- """
228
- Tag-delimited aggregate.
229
- Group type is deprecated and not supported in proto3. However, Proto3
230
- implementations should still be able to parse the group wire format and
231
- treat group fields as unknown fields.
232
- """
233
-
234
- TYPE_MESSAGE = 11
235
- """Length-delimited aggregate."""
236
-
237
- TYPE_BYTES = 12
238
- """New in version 2."""
239
-
240
- TYPE_UINT32 = 13
241
- """
242
-
243
- """
244
-
245
- TYPE_ENUM = 14
246
- """
247
-
248
- """
249
-
250
- TYPE_SFIXED32 = 15
251
- """
252
-
253
- """
254
-
255
- TYPE_SFIXED64 = 16
256
- """
257
-
258
- """
259
-
260
- TYPE_SINT32 = 17
261
- """Uses ZigZag encoding."""
262
-
263
- TYPE_SINT64 = 18
264
- """Uses ZigZag encoding."""
265
-
266
-
267
- class FieldDescriptorProtoLabel(betterproto2.Enum):
268
- """ """
269
-
270
- LABEL_OPTIONAL = 1
271
- """0 is reserved for errors"""
272
-
273
- LABEL_REQUIRED = 2
274
- """
275
-
276
- """
277
-
278
- LABEL_REPEATED = 3
279
- """
280
-
281
- """
282
-
283
-
284
- class FileOptionsOptimizeMode(betterproto2.Enum):
285
- """Generated classes can be optimized for speed or code size."""
286
-
287
- SPEED = 1
288
- """Generate complete code for parsing, serialization,"""
289
-
290
- CODE_SIZE = 2
291
- """
292
- etc.
293
-
294
- Use ReflectionOps to implement these methods.
295
- """
296
-
297
- LITE_RUNTIME = 3
298
- """Generate code using MessageLite and the lite runtime."""
299
-
300
-
301
- class FieldOptionsCType(betterproto2.Enum):
302
- """ """
303
-
304
- STRING = 0
305
- """Default mode."""
306
-
307
- CORD = 1
308
- """
309
-
310
- """
311
-
312
- STRING_PIECE = 2
313
- """
314
-
315
- """
316
-
317
-
318
- class FieldOptionsJsType(betterproto2.Enum):
319
- """ """
320
-
321
- JS_NORMAL = 0
322
- """Use the default type."""
323
-
324
- JS_STRING = 1
325
- """Use JavaScript strings."""
326
-
327
- JS_NUMBER = 2
328
- """Use JavaScript numbers."""
329
-
330
-
331
- class MethodOptionsIdempotencyLevel(betterproto2.Enum):
332
- """
333
- Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
334
- or neither? HTTP based RPC implementation may choose GET verb for safe
335
- methods, and PUT verb for idempotent methods instead of the default POST.
336
- """
337
-
338
- IDEMPOTENCY_UNKNOWN = 0
339
- """
340
-
341
- """
342
-
343
- NO_SIDE_EFFECTS = 1
344
- """implies idempotent"""
345
-
346
- IDEMPOTENT = 2
347
- """idempotent, but may have side effects"""
348
-
349
-
350
- class NullValue(betterproto2.Enum):
351
- """
352
- `NullValue` is a singleton enumeration to represent the null value for the
353
- `Value` type union.
354
-
355
- The JSON representation for `NullValue` is JSON `null`.
356
- """
357
-
358
- _ = 0
359
- """Null value."""
360
-
361
-
362
- @dataclass(eq=False, repr=False)
363
- class Any(betterproto2.Message):
364
- """
365
- `Any` contains an arbitrary serialized protocol buffer message along with a
366
- URL that describes the type of the serialized message.
367
-
368
- Protobuf library provides support to pack/unpack Any values in the form
369
- of utility functions or additional generated methods of the Any type.
370
-
371
- Example 1: Pack and unpack a message in C++.
372
-
373
- Foo foo = ...;
374
- Any any;
375
- any.PackFrom(foo);
376
- ...
377
- if (any.UnpackTo(&foo)) {
378
- ...
379
- }
380
-
381
- Example 2: Pack and unpack a message in Java.
382
-
383
- Foo foo = ...;
384
- Any any = Any.pack(foo);
385
- ...
386
- if (any.is(Foo.class)) {
387
- foo = any.unpack(Foo.class);
388
- }
389
-
390
- Example 3: Pack and unpack a message in Python.
391
-
392
- foo = Foo(...)
393
- any = Any()
394
- any.Pack(foo)
395
- ...
396
- if any.Is(Foo.DESCRIPTOR):
397
- any.Unpack(foo)
398
- ...
399
-
400
- Example 4: Pack and unpack a message in Go
401
-
402
- foo := &pb.Foo{...}
403
- any, err := ptypes.MarshalAny(foo)
404
- ...
405
- foo := &pb.Foo{}
406
- if err := ptypes.UnmarshalAny(any, foo); err != nil {
407
- ...
408
- }
409
-
410
- The pack methods provided by protobuf library will by default use
411
- 'type.googleapis.com/full.type.name' as the type URL and the unpack
412
- methods only use the fully qualified type name after the last '/'
413
- in the type URL, for example "foo.bar.com/x/y.z" will yield type
414
- name "y.z".
415
-
416
- JSON
417
- ====
418
- The JSON representation of an `Any` value uses the regular
419
- representation of the deserialized, embedded message, with an
420
- additional field `@type` which contains the type URL. Example:
421
-
422
- package google.profile;
423
- message Person {
424
- string first_name = 1;
425
- string last_name = 2;
426
- }
427
-
428
- {
429
- "@type": "type.googleapis.com/google.profile.Person",
430
- "firstName": <string>,
431
- "lastName": <string>
432
- }
433
-
434
- If the embedded message type is well-known and has a custom JSON
435
- representation, that representation will be embedded adding a field
436
- `value` which holds the custom JSON in addition to the `@type`
437
- field. Example (for message [google.protobuf.Duration][]):
438
-
439
- {
440
- "@type": "type.googleapis.com/google.protobuf.Duration",
441
- "value": "1.212s"
442
- }
443
- """
444
-
445
- type_url: str = betterproto2.string_field(1)
446
- """
447
- A URL/resource name that uniquely identifies the type of the serialized
448
- protocol buffer message. This string must contain at least
449
- one "/" character. The last segment of the URL's path must represent
450
- the fully qualified name of the type (as in
451
- `path/google.protobuf.Duration`). The name should be in a canonical form
452
- (e.g., leading "." is not accepted).
453
-
454
- In practice, teams usually precompile into the binary all types that they
455
- expect it to use in the context of Any. However, for URLs which use the
456
- scheme `http`, `https`, or no scheme, one can optionally set up a type
457
- server that maps type URLs to message definitions as follows:
458
-
459
- * If no scheme is provided, `https` is assumed.
460
- * An HTTP GET on the URL must yield a [google.protobuf.Type][]
461
- value in binary format, or produce an error.
462
- * Applications are allowed to cache lookup results based on the
463
- URL, or have them precompiled into a binary to avoid any
464
- lookup. Therefore, binary compatibility needs to be preserved
465
- on changes to types. (Use versioned type names to manage
466
- breaking changes.)
467
-
468
- Note: this functionality is not currently available in the official
469
- protobuf release, and it is not used for type URLs beginning with
470
- type.googleapis.com.
471
-
472
- Schemes other than `http`, `https` (or the empty scheme) might be
473
- used with implementation specific semantics.
474
- """
475
-
476
- value: bytes = betterproto2.bytes_field(2)
477
- """
478
- Must be a valid serialized protocol buffer of the above specified type.
479
- """
480
-
481
-
482
- @dataclass(eq=False, repr=False)
483
- class SourceContext(betterproto2.Message):
484
- """
485
- `SourceContext` represents information about the source of a
486
- protobuf element, like the file in which it is defined.
487
- """
488
-
489
- file_name: str = betterproto2.string_field(1)
490
- """
491
- The path-qualified name of the .proto file that contained the associated
492
- protobuf element. For example: `"google/protobuf/source_context.proto"`.
493
- """
494
-
495
-
496
- @dataclass(eq=False, repr=False)
497
- class Type(betterproto2.Message):
498
- """A protocol buffer message type."""
499
-
500
- name: str = betterproto2.string_field(1)
501
- """The fully qualified message name."""
502
-
503
- fields: List["Field"] = betterproto2.message_field(2, repeated=True)
504
- """The list of fields."""
505
-
506
- oneofs: List[str] = betterproto2.string_field(3, repeated=True)
507
- """The list of types appearing in `oneof` definitions in this type."""
508
-
509
- options: List["Option"] = betterproto2.message_field(4, repeated=True)
510
- """The protocol buffer options."""
511
-
512
- source_context: "SourceContext" = betterproto2.message_field(5)
513
- """The source context."""
514
-
515
- syntax: "Syntax" = betterproto2.enum_field(6, enum_default_value=lambda: Syntax.try_value(0))
516
- """The source syntax."""
517
-
518
-
519
- @dataclass(eq=False, repr=False)
520
- class Field(betterproto2.Message):
521
- """A single field of a message type."""
522
-
523
- kind: "FieldKind" = betterproto2.enum_field(1, enum_default_value=lambda: FieldKind.try_value(0))
524
- """The field type."""
525
-
526
- cardinality: "FieldCardinality" = betterproto2.enum_field(
527
- 2, enum_default_value=lambda: FieldCardinality.try_value(0)
528
- )
529
- """The field cardinality."""
530
-
531
- number: int = betterproto2.int32_field(3)
532
- """The field number."""
533
-
534
- name: str = betterproto2.string_field(4)
535
- """The field name."""
536
-
537
- type_url: str = betterproto2.string_field(6)
538
- """
539
- The field type URL, without the scheme, for message or enumeration
540
- types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
541
- """
542
-
543
- oneof_index: int = betterproto2.int32_field(7)
544
- """
545
- The index of the field type in `Type.oneofs`, for message or enumeration
546
- types. The first type has index 1; zero means the type is not in the list.
547
- """
548
-
549
- packed: bool = betterproto2.bool_field(8)
550
- """Whether to use alternative packed wire representation."""
551
-
552
- options: List["Option"] = betterproto2.message_field(9, repeated=True)
553
- """The protocol buffer options."""
554
-
555
- json_name: str = betterproto2.string_field(10)
556
- """The field JSON name."""
557
-
558
- default_value: str = betterproto2.string_field(11)
559
- """
560
- The string value of the default value of this field. Proto2 syntax only.
561
- """
562
-
563
-
564
- @dataclass(eq=False, repr=False)
565
- class Enum(betterproto2.Message):
566
- """Enum type definition."""
567
-
568
- name: str = betterproto2.string_field(1)
569
- """Enum type name."""
570
-
571
- enumvalue: List["EnumValue"] = betterproto2.message_field(2, wraps=betterproto2.TYPE_ENUM, repeated=True)
572
- """Enum value definitions."""
573
-
574
- options: List["Option"] = betterproto2.message_field(3, repeated=True)
575
- """Protocol buffer options."""
576
-
577
- source_context: "SourceContext" = betterproto2.message_field(4)
578
- """The source context."""
579
-
580
- syntax: "Syntax" = betterproto2.enum_field(5, enum_default_value=lambda: Syntax.try_value(0))
581
- """The source syntax."""
582
-
583
-
584
- @dataclass(eq=False, repr=False)
585
- class EnumValue(betterproto2.Message):
586
- """Enum value definition."""
587
-
588
- name: str = betterproto2.string_field(1)
589
- """Enum value name."""
590
-
591
- number: int = betterproto2.int32_field(2)
592
- """Enum value number."""
593
-
594
- options: List["Option"] = betterproto2.message_field(3, repeated=True)
595
- """Protocol buffer options."""
596
-
597
-
598
- @dataclass(eq=False, repr=False)
599
- class Option(betterproto2.Message):
600
- """
601
- A protocol buffer option, which can be attached to a message, field,
602
- enumeration, etc.
603
- """
604
-
605
- name: str = betterproto2.string_field(1)
606
- """
607
- The option's name. For protobuf built-in options (options defined in
608
- descriptor.proto), this is the short name. For example, `"map_entry"`.
609
- For custom options, it should be the fully-qualified name. For example,
610
- `"google.api.http"`.
611
- """
612
-
613
- value: "Any" = betterproto2.message_field(2)
614
- """
615
- The option's value packed in an Any message. If the value is a primitive,
616
- the corresponding wrapper type defined in google/protobuf/wrappers.proto
617
- should be used. If the value is an enum, it should be stored as an int32
618
- value using the google.protobuf.Int32Value type.
619
- """
620
-
621
-
622
- @dataclass(eq=False, repr=False)
623
- class Api(betterproto2.Message):
624
- """
625
- Api is a light-weight descriptor for an API Interface.
626
-
627
- Interfaces are also described as "protocol buffer services" in some contexts,
628
- such as by the "service" keyword in a .proto file, but they are different
629
- from API Services, which represent a concrete implementation of an interface
630
- as opposed to simply a description of methods and bindings. They are also
631
- sometimes simply referred to as "APIs" in other contexts, such as the name of
632
- this message itself. See https://cloud.google.com/apis/design/glossary for
633
- detailed terminology.
634
- """
635
-
636
- name: str = betterproto2.string_field(1)
637
- """
638
- The fully qualified name of this interface, including package name
639
- followed by the interface's simple name.
640
- """
641
-
642
- methods: List["Method"] = betterproto2.message_field(2, repeated=True)
643
- """The methods of this interface, in unspecified order."""
644
-
645
- options: List["Option"] = betterproto2.message_field(3, repeated=True)
646
- """Any metadata attached to the interface."""
647
-
648
- version: str = betterproto2.string_field(4)
649
- """
650
- A version string for this interface. If specified, must have the form
651
- `major-version.minor-version`, as in `1.10`. If the minor version is
652
- omitted, it defaults to zero. If the entire version field is empty, the
653
- major version is derived from the package name, as outlined below. If the
654
- field is not empty, the version in the package name will be verified to be
655
- consistent with what is provided here.
656
-
657
- The versioning schema uses [semantic
658
- versioning](http://semver.org) where the major version number
659
- indicates a breaking change and the minor version an additive,
660
- non-breaking change. Both version numbers are signals to users
661
- what to expect from different versions, and should be carefully
662
- chosen based on the product plan.
663
-
664
- The major version is also reflected in the package name of the
665
- interface, which must end in `v<major-version>`, as in
666
- `google.feature.v1`. For major versions 0 and 1, the suffix can
667
- be omitted. Zero major versions must only be used for
668
- experimental, non-GA interfaces.
669
- """
670
-
671
- source_context: "SourceContext" = betterproto2.message_field(5)
672
- """
673
- Source context for the protocol buffer service represented by this
674
- message.
675
- """
676
-
677
- mixins: List["Mixin"] = betterproto2.message_field(6, repeated=True)
678
- """Included interfaces. See [Mixin][]."""
679
-
680
- syntax: "Syntax" = betterproto2.enum_field(7, enum_default_value=lambda: Syntax.try_value(0))
681
- """The source syntax of the service."""
682
-
683
-
684
- @dataclass(eq=False, repr=False)
685
- class Method(betterproto2.Message):
686
- """Method represents a method of an API interface."""
687
-
688
- name: str = betterproto2.string_field(1)
689
- """The simple name of this method."""
690
-
691
- request_type_url: str = betterproto2.string_field(2)
692
- """A URL of the input message type."""
693
-
694
- request_streaming: bool = betterproto2.bool_field(3)
695
- """If true, the request is streamed."""
696
-
697
- response_type_url: str = betterproto2.string_field(4)
698
- """The URL of the output message type."""
699
-
700
- response_streaming: bool = betterproto2.bool_field(5)
701
- """If true, the response is streamed."""
702
-
703
- options: List["Option"] = betterproto2.message_field(6, repeated=True)
704
- """Any metadata attached to the method."""
705
-
706
- syntax: "Syntax" = betterproto2.enum_field(7, enum_default_value=lambda: Syntax.try_value(0))
707
- """The source syntax of this method."""
708
-
709
-
710
- @dataclass(eq=False, repr=False)
711
- class Mixin(betterproto2.Message):
712
- """
713
- Declares an API Interface to be included in this interface. The including
714
- interface must redeclare all the methods from the included interface, but
715
- documentation and options are inherited as follows:
716
-
717
- - If after comment and whitespace stripping, the documentation
718
- string of the redeclared method is empty, it will be inherited
719
- from the original method.
720
-
721
- - Each annotation belonging to the service config (http,
722
- visibility) which is not set in the redeclared method will be
723
- inherited.
724
-
725
- - If an http annotation is inherited, the path pattern will be
726
- modified as follows. Any version prefix will be replaced by the
727
- version of the including interface plus the [root][] path if
728
- specified.
729
-
730
- Example of a simple mixin:
731
-
732
- package google.acl.v1;
733
- service AccessControl {
734
- // Get the underlying ACL object.
735
- rpc GetAcl(GetAclRequest) returns (Acl) {
736
- option (google.api.http).get = "/v1/{resource=**}:getAcl";
737
- }
738
- }
739
-
740
- package google.storage.v2;
741
- service Storage {
742
- rpc GetAcl(GetAclRequest) returns (Acl);
743
-
744
- // Get a data record.
745
- rpc GetData(GetDataRequest) returns (Data) {
746
- option (google.api.http).get = "/v2/{resource=**}";
747
- }
748
- }
749
-
750
- Example of a mixin configuration:
751
-
752
- apis:
753
- - name: google.storage.v2.Storage
754
- mixins:
755
- - name: google.acl.v1.AccessControl
756
-
757
- The mixin construct implies that all methods in `AccessControl` are
758
- also declared with same name and request/response types in
759
- `Storage`. A documentation generator or annotation processor will
760
- see the effective `Storage.GetAcl` method after inherting
761
- documentation and annotations as follows:
762
-
763
- service Storage {
764
- // Get the underlying ACL object.
765
- rpc GetAcl(GetAclRequest) returns (Acl) {
766
- option (google.api.http).get = "/v2/{resource=**}:getAcl";
767
- }
768
- ...
769
- }
770
-
771
- Note how the version in the path pattern changed from `v1` to `v2`.
772
-
773
- If the `root` field in the mixin is specified, it should be a
774
- relative path under which inherited HTTP paths are placed. Example:
775
-
776
- apis:
777
- - name: google.storage.v2.Storage
778
- mixins:
779
- - name: google.acl.v1.AccessControl
780
- root: acls
781
-
782
- This implies the following inherited HTTP annotation:
783
-
784
- service Storage {
785
- // Get the underlying ACL object.
786
- rpc GetAcl(GetAclRequest) returns (Acl) {
787
- option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
788
- }
789
- ...
790
- }
791
- """
792
-
793
- name: str = betterproto2.string_field(1)
794
- """The fully qualified name of the interface which is included."""
795
-
796
- root: str = betterproto2.string_field(2)
797
- """
798
- If non-empty specifies a path under which inherited HTTP paths
799
- are rooted.
800
- """
801
-
802
-
803
- @dataclass(eq=False, repr=False)
804
- class FileDescriptorSet(betterproto2.Message):
805
- """
806
- The protocol compiler can output a FileDescriptorSet containing the .proto
807
- files it parses.
808
- """
809
-
810
- file: List["FileDescriptorProto"] = betterproto2.message_field(1, repeated=True)
811
- """
812
-
813
- """
814
-
815
-
816
- @dataclass(eq=False, repr=False)
817
- class FileDescriptorProto(betterproto2.Message):
818
- """Describes a complete .proto file."""
819
-
820
- name: str = betterproto2.string_field(1)
821
- """file name, relative to root of source tree"""
822
-
823
- package: str = betterproto2.string_field(2)
824
- """e.g. "foo", "foo.bar", etc."""
825
-
826
- dependency: List[str] = betterproto2.string_field(3, repeated=True)
827
- """Names of files imported by this file."""
828
-
829
- public_dependency: List[int] = betterproto2.int32_field(10, repeated=True)
830
- """Indexes of the public imported files in the dependency list above."""
831
-
832
- weak_dependency: List[int] = betterproto2.int32_field(11, repeated=True)
833
- """
834
- Indexes of the weak imported files in the dependency list.
835
- For Google-internal migration only. Do not use.
836
- """
837
-
838
- message_type: List["DescriptorProto"] = betterproto2.message_field(4, repeated=True)
839
- """All top-level definitions in this file."""
840
-
841
- enum_type: List["EnumDescriptorProto"] = betterproto2.message_field(5, repeated=True)
842
- """
843
-
844
- """
845
-
846
- service: List["ServiceDescriptorProto"] = betterproto2.message_field(6, repeated=True)
847
- """
848
-
849
- """
850
-
851
- extension: List["FieldDescriptorProto"] = betterproto2.message_field(7, repeated=True)
852
- """
853
-
854
- """
855
-
856
- options: "FileOptions" = betterproto2.message_field(8)
857
- """
858
-
859
- """
860
-
861
- source_code_info: "SourceCodeInfo" = betterproto2.message_field(9)
862
- """
863
- This field contains optional information about the original source code.
864
- You may safely remove this entire field without harming runtime
865
- functionality of the descriptors -- the information is needed only by
866
- development tools.
867
- """
868
-
869
- syntax: str = betterproto2.string_field(12)
870
- """
871
- The syntax of the proto file.
872
- The supported values are "proto2" and "proto3".
873
- """
874
-
875
-
876
- @dataclass(eq=False, repr=False)
877
- class DescriptorProto(betterproto2.Message):
878
- """Describes a message type."""
879
-
880
- name: str = betterproto2.string_field(1)
881
- """
882
-
883
- """
884
-
885
- field: List["FieldDescriptorProto"] = betterproto2.message_field(2, repeated=True)
886
- """
887
-
888
- """
889
-
890
- extension: List["FieldDescriptorProto"] = betterproto2.message_field(6, repeated=True)
891
- """
892
-
893
- """
894
-
895
- nested_type: List["DescriptorProto"] = betterproto2.message_field(3, repeated=True)
896
- """
897
-
898
- """
899
-
900
- enum_type: List["EnumDescriptorProto"] = betterproto2.message_field(4, repeated=True)
901
- """
902
-
903
- """
904
-
905
- extension_range: List["DescriptorProtoExtensionRange"] = betterproto2.message_field(5, repeated=True)
906
- """
907
-
908
- """
909
-
910
- oneof_decl: List["OneofDescriptorProto"] = betterproto2.message_field(8, repeated=True)
911
- """
912
-
913
- """
914
-
915
- options: "MessageOptions" = betterproto2.message_field(7)
916
- """
917
-
918
- """
919
-
920
- reserved_range: List["DescriptorProtoReservedRange"] = betterproto2.message_field(9, repeated=True)
921
- """
922
-
923
- """
924
-
925
- reserved_name: List[str] = betterproto2.string_field(10, repeated=True)
926
- """
927
- Reserved field names, which may not be used by fields in the same message.
928
- A given name may only be reserved once.
929
- """
930
-
931
-
932
- @dataclass(eq=False, repr=False)
933
- class DescriptorProtoExtensionRange(betterproto2.Message):
934
- """ """
935
-
936
- start: int = betterproto2.int32_field(1)
937
- """Inclusive."""
938
-
939
- end: int = betterproto2.int32_field(2)
940
- """Exclusive."""
941
-
942
- options: "ExtensionRangeOptions" = betterproto2.message_field(3)
943
- """
944
-
945
- """
946
-
947
-
948
- @dataclass(eq=False, repr=False)
949
- class DescriptorProtoReservedRange(betterproto2.Message):
950
- """
951
- Range of reserved tag numbers. Reserved tag numbers may not be used by
952
- fields or extension ranges in the same message. Reserved ranges may
953
- not overlap.
954
- """
955
-
956
- start: int = betterproto2.int32_field(1)
957
- """Inclusive."""
958
-
959
- end: int = betterproto2.int32_field(2)
960
- """Exclusive."""
961
-
962
-
963
- @dataclass(eq=False, repr=False)
964
- class ExtensionRangeOptions(betterproto2.Message):
965
- """ """
966
-
967
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
968
- """The parser stores options it doesn't recognize here. See above."""
969
-
970
-
971
- @dataclass(eq=False, repr=False)
972
- class FieldDescriptorProto(betterproto2.Message):
973
- """Describes a field within a message."""
974
-
975
- name: str = betterproto2.string_field(1)
976
- """
977
-
978
- """
979
-
980
- number: int = betterproto2.int32_field(3)
981
- """
982
-
983
- """
984
-
985
- label: "FieldDescriptorProtoLabel" = betterproto2.enum_field(
986
- 4, enum_default_value=lambda: FieldDescriptorProtoLabel.try_value(0)
987
- )
988
- """
989
-
990
- """
991
-
992
- type: "FieldDescriptorProtoType" = betterproto2.enum_field(
993
- 5, enum_default_value=lambda: FieldDescriptorProtoType.try_value(0)
994
- )
995
- """
996
- If type_name is set, this need not be set. If both this and type_name
997
- are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
998
- """
999
-
1000
- type_name: str = betterproto2.string_field(6)
1001
- """
1002
- For message and enum types, this is the name of the type. If the name
1003
- starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
1004
- rules are used to find the type (i.e. first the nested types within this
1005
- message are searched, then within the parent, on up to the root
1006
- namespace).
1007
- """
1008
-
1009
- extendee: str = betterproto2.string_field(2)
1010
- """
1011
- For extensions, this is the name of the type being extended. It is
1012
- resolved in the same manner as type_name.
1013
- """
1014
-
1015
- default_value: str = betterproto2.string_field(7)
1016
- """
1017
- For numeric types, contains the original text representation of the value.
1018
- For booleans, "true" or "false".
1019
- For strings, contains the default text contents (not escaped in any way).
1020
- For bytes, contains the C escaped value. All bytes >= 128 are escaped.
1021
- TODO(kenton): Base-64 encode?
1022
- """
1023
-
1024
- oneof_index: int | None = betterproto2.int32_field(9, optional=True)
1025
- """
1026
- If set, gives the index of a oneof in the containing type's oneof_decl
1027
- list. This field is a member of that oneof.
1028
- """
1029
-
1030
- json_name: str = betterproto2.string_field(10)
1031
- """
1032
- JSON name of this field. The value is set by protocol compiler. If the
1033
- user has set a "json_name" option on this field, that option's value
1034
- will be used. Otherwise, it's deduced from the field's name by converting
1035
- it to camelCase.
1036
- """
1037
-
1038
- options: "FieldOptions" = betterproto2.message_field(8)
1039
- """
1040
-
1041
- """
1042
-
1043
- proto3_optional: bool = betterproto2.bool_field(17)
1044
- """
1045
- If true, this is a proto3 "optional". When a proto3 field is optional, it
1046
- tracks presence regardless of field type.
1047
-
1048
- When proto3_optional is true, this field must be belong to a oneof to
1049
- signal to old proto3 clients that presence is tracked for this field. This
1050
- oneof is known as a "synthetic" oneof, and this field must be its sole
1051
- member (each proto3 optional field gets its own synthetic oneof). Synthetic
1052
- oneofs exist in the descriptor only, and do not generate any API. Synthetic
1053
- oneofs must be ordered after all "real" oneofs.
1054
-
1055
- For message fields, proto3_optional doesn't create any semantic change,
1056
- since non-repeated message fields always track presence. However it still
1057
- indicates the semantic detail of whether the user wrote "optional" or not.
1058
- This can be useful for round-tripping the .proto file. For consistency we
1059
- give message fields a synthetic oneof also, even though it is not required
1060
- to track presence. This is especially important because the parser can't
1061
- tell if a field is a message or an enum, so it must always create a
1062
- synthetic oneof.
1063
-
1064
- Proto2 optional fields do not set this flag, because they already indicate
1065
- optional with `LABEL_OPTIONAL`.
1066
- """
1067
-
1068
-
1069
- @dataclass(eq=False, repr=False)
1070
- class OneofDescriptorProto(betterproto2.Message):
1071
- """Describes a oneof."""
1072
-
1073
- name: str = betterproto2.string_field(1)
1074
- """
1075
-
1076
- """
1077
-
1078
- options: "OneofOptions" = betterproto2.message_field(2)
1079
- """
1080
-
1081
- """
1082
-
1083
-
1084
- @dataclass(eq=False, repr=False)
1085
- class EnumDescriptorProto(betterproto2.Message):
1086
- """Describes an enum type."""
1087
-
1088
- name: str = betterproto2.string_field(1)
1089
- """
1090
-
1091
- """
1092
-
1093
- value: List["EnumValueDescriptorProto"] = betterproto2.message_field(2, repeated=True)
1094
- """
1095
-
1096
- """
1097
-
1098
- options: "EnumOptions" = betterproto2.message_field(3)
1099
- """
1100
-
1101
- """
1102
-
1103
- reserved_range: List["EnumDescriptorProtoEnumReservedRange"] = betterproto2.message_field(4, repeated=True)
1104
- """
1105
- Range of reserved numeric values. Reserved numeric values may not be used
1106
- by enum values in the same enum declaration. Reserved ranges may not
1107
- overlap.
1108
- """
1109
-
1110
- reserved_name: List[str] = betterproto2.string_field(5, repeated=True)
1111
- """
1112
- Reserved enum value names, which may not be reused. A given name may only
1113
- be reserved once.
1114
- """
1115
-
1116
-
1117
- @dataclass(eq=False, repr=False)
1118
- class EnumDescriptorProtoEnumReservedRange(betterproto2.Message):
1119
- """
1120
- Range of reserved numeric values. Reserved values may not be used by
1121
- entries in the same enum. Reserved ranges may not overlap.
1122
-
1123
- Note that this is distinct from DescriptorProto.ReservedRange in that it
1124
- is inclusive such that it can appropriately represent the entire int32
1125
- domain.
1126
- """
1127
-
1128
- start: int = betterproto2.int32_field(1)
1129
- """Inclusive."""
1130
-
1131
- end: int = betterproto2.int32_field(2)
1132
- """Inclusive."""
1133
-
1134
-
1135
- @dataclass(eq=False, repr=False)
1136
- class EnumValueDescriptorProto(betterproto2.Message):
1137
- """Describes a value within an enum."""
1138
-
1139
- name: str = betterproto2.string_field(1)
1140
- """
1141
-
1142
- """
1143
-
1144
- number: int = betterproto2.int32_field(2)
1145
- """
1146
-
1147
- """
1148
-
1149
- options: "EnumValueOptions" = betterproto2.message_field(3)
1150
- """
1151
-
1152
- """
1153
-
1154
-
1155
- @dataclass(eq=False, repr=False)
1156
- class ServiceDescriptorProto(betterproto2.Message):
1157
- """Describes a service."""
1158
-
1159
- name: str = betterproto2.string_field(1)
1160
- """
1161
-
1162
- """
1163
-
1164
- method: List["MethodDescriptorProto"] = betterproto2.message_field(2, repeated=True)
1165
- """
1166
-
1167
- """
1168
-
1169
- options: "ServiceOptions" = betterproto2.message_field(3)
1170
- """
1171
-
1172
- """
1173
-
1174
-
1175
- @dataclass(eq=False, repr=False)
1176
- class MethodDescriptorProto(betterproto2.Message):
1177
- """Describes a method of a service."""
1178
-
1179
- name: str = betterproto2.string_field(1)
1180
- """
1181
-
1182
- """
1183
-
1184
- input_type: str = betterproto2.string_field(2)
1185
- """
1186
- Input and output type names. These are resolved in the same way as
1187
- FieldDescriptorProto.type_name, but must refer to a message type.
1188
- """
1189
-
1190
- output_type: str = betterproto2.string_field(3)
1191
- """
1192
-
1193
- """
1194
-
1195
- options: "MethodOptions" = betterproto2.message_field(4)
1196
- """
1197
-
1198
- """
1199
-
1200
- client_streaming: bool = betterproto2.bool_field(5)
1201
- """Identifies if client streams multiple client messages"""
1202
-
1203
- server_streaming: bool = betterproto2.bool_field(6)
1204
- """Identifies if server streams multiple server messages"""
1205
-
1206
-
1207
- @dataclass(eq=False, repr=False)
1208
- class FileOptions(betterproto2.Message):
1209
- """
1210
- ===================================================================
1211
- Options
1212
-
1213
- Each of the definitions above may have "options" attached. These are
1214
- just annotations which may cause code to be generated slightly differently
1215
- or may contain hints for code that manipulates protocol messages.
1216
-
1217
- Clients may define custom options as extensions of the *Options messages.
1218
- These extensions may not yet be known at parsing time, so the parser cannot
1219
- store the values in them. Instead it stores them in a field in the *Options
1220
- message called uninterpreted_option. This field must have the same name
1221
- across all *Options messages. We then use this field to populate the
1222
- extensions when we build a descriptor, at which point all protos have been
1223
- parsed and so all extensions are known.
1224
-
1225
- Extension numbers for custom options may be chosen as follows:
1226
- * For options which will only be used within a single application or
1227
- organization, or for experimental options, use field numbers 50000
1228
- through 99999. It is up to you to ensure that you do not use the
1229
- same number for multiple options.
1230
- * For options which will be published and used publicly by multiple
1231
- independent entities, e-mail protobuf-global-extension-registry@google.com
1232
- to reserve extension numbers. Simply provide your project name (e.g.
1233
- Objective-C plugin) and your project website (if available) -- there's no
1234
- need to explain how you intend to use them. Usually you only need one
1235
- extension number. You can declare multiple options with only one extension
1236
- number by putting them in a sub-message. See the Custom Options section of
1237
- the docs for examples:
1238
- https://developers.google.com/protocol-buffers/docs/proto#options
1239
- If this turns out to be popular, a web service will be set up
1240
- to automatically assign option numbers.
1241
- """
1242
-
1243
- java_package: str = betterproto2.string_field(1)
1244
- """
1245
- Sets the Java package where classes generated from this .proto will be
1246
- placed. By default, the proto package is used, but this is often
1247
- inappropriate because proto packages do not normally start with backwards
1248
- domain names.
1249
- """
1250
-
1251
- java_outer_classname: str = betterproto2.string_field(8)
1252
- """
1253
- If set, all the classes from the .proto file are wrapped in a single
1254
- outer class with the given name. This applies to both Proto1
1255
- (equivalent to the old "--one_java_file" option) and Proto2 (where
1256
- a .proto always translates to a single class, but you may want to
1257
- explicitly choose the class name).
1258
- """
1259
-
1260
- java_multiple_files: bool = betterproto2.bool_field(10)
1261
- """
1262
- If set true, then the Java code generator will generate a separate .java
1263
- file for each top-level message, enum, and service defined in the .proto
1264
- file. Thus, these types will *not* be nested inside the outer class
1265
- named by java_outer_classname. However, the outer class will still be
1266
- generated to contain the file's getDescriptor() method as well as any
1267
- top-level extensions defined in the file.
1268
- """
1269
-
1270
- java_generate_equals_and_hash: bool = betterproto2.bool_field(20)
1271
- """This option does nothing."""
1272
-
1273
- java_string_check_utf8: bool = betterproto2.bool_field(27)
1274
- """
1275
- If set true, then the Java2 code generator will generate code that
1276
- throws an exception whenever an attempt is made to assign a non-UTF-8
1277
- byte sequence to a string field.
1278
- Message reflection will do the same.
1279
- However, an extension field still accepts non-UTF-8 byte sequences.
1280
- This option has no effect on when used with the lite runtime.
1281
- """
1282
-
1283
- optimize_for: "FileOptionsOptimizeMode" = betterproto2.enum_field(
1284
- 9, enum_default_value=lambda: FileOptionsOptimizeMode.try_value(0)
1285
- )
1286
- """
1287
-
1288
- """
1289
-
1290
- go_package: str = betterproto2.string_field(11)
1291
- """
1292
- Sets the Go package where structs generated from this .proto will be
1293
- placed. If omitted, the Go package will be derived from the following:
1294
- - The basename of the package import path, if provided.
1295
- - Otherwise, the package statement in the .proto file, if present.
1296
- - Otherwise, the basename of the .proto file, without extension.
1297
- """
1298
-
1299
- cc_generic_services: bool = betterproto2.bool_field(16)
1300
- """
1301
- Should generic services be generated in each language? "Generic" services
1302
- are not specific to any particular RPC system. They are generated by the
1303
- main code generators in each language (without additional plugins).
1304
- Generic services were the only kind of service generation supported by
1305
- early versions of google.protobuf.
1306
-
1307
- Generic services are now considered deprecated in favor of using plugins
1308
- that generate code specific to your particular RPC system. Therefore,
1309
- these default to false. Old code which depends on generic services should
1310
- explicitly set them to true.
1311
- """
1312
-
1313
- java_generic_services: bool = betterproto2.bool_field(17)
1314
- """
1315
-
1316
- """
1317
-
1318
- py_generic_services: bool = betterproto2.bool_field(18)
1319
- """
1320
-
1321
- """
1322
-
1323
- php_generic_services: bool = betterproto2.bool_field(42)
1324
- """
1325
-
1326
- """
1327
-
1328
- deprecated: bool = betterproto2.bool_field(23)
1329
- """
1330
- Is this file deprecated?
1331
- Depending on the target platform, this can emit Deprecated annotations
1332
- for everything in the file, or it will be completely ignored; in the very
1333
- least, this is a formalization for deprecating files.
1334
- """
1335
-
1336
- cc_enable_arenas: bool = betterproto2.bool_field(31)
1337
- """
1338
- Enables the use of arenas for the proto messages in this file. This applies
1339
- only to generated classes for C++.
1340
- """
1341
-
1342
- objc_class_prefix: str = betterproto2.string_field(36)
1343
- """
1344
- Sets the objective c class prefix which is prepended to all objective c
1345
- generated classes from this .proto. There is no default.
1346
- """
1347
-
1348
- csharp_namespace: str = betterproto2.string_field(37)
1349
- """Namespace for generated classes; defaults to the package."""
1350
-
1351
- swift_prefix: str = betterproto2.string_field(39)
1352
- """
1353
- By default Swift generators will take the proto package and CamelCase it
1354
- replacing '.' with underscore and use that to prefix the types/symbols
1355
- defined. When this options is provided, they will use this value instead
1356
- to prefix the types/symbols defined.
1357
- """
1358
-
1359
- php_class_prefix: str = betterproto2.string_field(40)
1360
- """
1361
- Sets the php class prefix which is prepended to all php generated classes
1362
- from this .proto. Default is empty.
1363
- """
1364
-
1365
- php_namespace: str = betterproto2.string_field(41)
1366
- """
1367
- Use this option to change the namespace of php generated classes. Default
1368
- is empty. When this option is empty, the package name will be used for
1369
- determining the namespace.
1370
- """
1371
-
1372
- php_metadata_namespace: str = betterproto2.string_field(44)
1373
- """
1374
- Use this option to change the namespace of php generated metadata classes.
1375
- Default is empty. When this option is empty, the proto file name will be
1376
- used for determining the namespace.
1377
- """
1378
-
1379
- ruby_package: str = betterproto2.string_field(45)
1380
- """
1381
- Use this option to change the package of ruby generated classes. Default
1382
- is empty. When this option is not set, the package name will be used for
1383
- determining the ruby package.
1384
- """
1385
-
1386
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1387
- """
1388
- The parser stores options it doesn't recognize here.
1389
- See the documentation for the "Options" section above.
1390
- """
1391
-
1392
- def __post_init__(self) -> None:
1393
- super().__post_init__()
1394
- if self.is_set("java_generate_equals_and_hash"):
1395
- warnings.warn(
1396
- "FileOptions.java_generate_equals_and_hash is deprecated",
1397
- DeprecationWarning,
1398
- )
1399
-
1400
-
1401
- @dataclass(eq=False, repr=False)
1402
- class MessageOptions(betterproto2.Message):
1403
- """ """
1404
-
1405
- message_set_wire_format: bool = betterproto2.bool_field(1)
1406
- """
1407
- Set true to use the old proto1 MessageSet wire format for extensions.
1408
- This is provided for backwards-compatibility with the MessageSet wire
1409
- format. You should not use this for any other reason: It's less
1410
- efficient, has fewer features, and is more complicated.
1411
-
1412
- The message must be defined exactly as follows:
1413
- message Foo {
1414
- option message_set_wire_format = true;
1415
- extensions 4 to max;
1416
- }
1417
- Note that the message cannot have any defined fields; MessageSets only
1418
- have extensions.
1419
-
1420
- All extensions of your type must be singular messages; e.g. they cannot
1421
- be int32s, enums, or repeated messages.
1422
-
1423
- Because this is an option, the above two restrictions are not enforced by
1424
- the protocol compiler.
1425
- """
1426
-
1427
- no_standard_descriptor_accessor: bool = betterproto2.bool_field(2)
1428
- """
1429
- Disables the generation of the standard "descriptor()" accessor, which can
1430
- conflict with a field of the same name. This is meant to make migration
1431
- from proto1 easier; new code should avoid fields named "descriptor".
1432
- """
1433
-
1434
- deprecated: bool = betterproto2.bool_field(3)
1435
- """
1436
- Is this message deprecated?
1437
- Depending on the target platform, this can emit Deprecated annotations
1438
- for the message, or it will be completely ignored; in the very least,
1439
- this is a formalization for deprecating messages.
1440
- """
1441
-
1442
- map_entry: bool = betterproto2.bool_field(7)
1443
- """
1444
- Whether the message is an automatically generated map entry type for the
1445
- maps field.
1446
-
1447
- For maps fields:
1448
- map<KeyType, ValueType> map_field = 1;
1449
- The parsed descriptor looks like:
1450
- message MapFieldEntry {
1451
- option map_entry = true;
1452
- optional KeyType key = 1;
1453
- optional ValueType value = 2;
1454
- }
1455
- repeated MapFieldEntry map_field = 1;
1456
-
1457
- Implementations may choose not to generate the map_entry=true message, but
1458
- use a native map in the target language to hold the keys and values.
1459
- The reflection APIs in such implementations still need to work as
1460
- if the field is a repeated message field.
1461
-
1462
- NOTE: Do not set the option in .proto files. Always use the maps syntax
1463
- instead. The option should only be implicitly set by the proto compiler
1464
- parser.
1465
- """
1466
-
1467
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1468
- """The parser stores options it doesn't recognize here. See above."""
1469
-
1470
-
1471
- @dataclass(eq=False, repr=False)
1472
- class FieldOptions(betterproto2.Message):
1473
- """ """
1474
-
1475
- ctype: "FieldOptionsCType" = betterproto2.enum_field(1, enum_default_value=lambda: FieldOptionsCType.try_value(0))
1476
- """
1477
- The ctype option instructs the C++ code generator to use a different
1478
- representation of the field than it normally would. See the specific
1479
- options below. This option is not yet implemented in the open source
1480
- release -- sorry, we'll try to include it in a future version!
1481
- """
1482
-
1483
- packed: bool = betterproto2.bool_field(2)
1484
- """
1485
- The packed option can be enabled for repeated primitive fields to enable
1486
- a more efficient representation on the wire. Rather than repeatedly
1487
- writing the tag and type for each element, the entire array is encoded as
1488
- a single length-delimited blob. In proto3, only explicit setting it to
1489
- false will avoid using packed encoding.
1490
- """
1491
-
1492
- jstype: "FieldOptionsJsType" = betterproto2.enum_field(
1493
- 6, enum_default_value=lambda: FieldOptionsJsType.try_value(0)
1494
- )
1495
- """
1496
- The jstype option determines the JavaScript type used for values of the
1497
- field. The option is permitted only for 64 bit integral and fixed types
1498
- (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
1499
- is represented as JavaScript string, which avoids loss of precision that
1500
- can happen when a large value is converted to a floating point JavaScript.
1501
- Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
1502
- use the JavaScript "number" type. The behavior of the default option
1503
- JS_NORMAL is implementation dependent.
1504
-
1505
- This option is an enum to permit additional types to be added, e.g.
1506
- goog.math.Integer.
1507
- """
1508
-
1509
- lazy: bool = betterproto2.bool_field(5)
1510
- """
1511
- Should this field be parsed lazily? Lazy applies only to message-type
1512
- fields. It means that when the outer message is initially parsed, the
1513
- inner message's contents will not be parsed but instead stored in encoded
1514
- form. The inner message will actually be parsed when it is first accessed.
1515
-
1516
- This is only a hint. Implementations are free to choose whether to use
1517
- eager or lazy parsing regardless of the value of this option. However,
1518
- setting this option true suggests that the protocol author believes that
1519
- using lazy parsing on this field is worth the additional bookkeeping
1520
- overhead typically needed to implement it.
1521
-
1522
- This option does not affect the public interface of any generated code;
1523
- all method signatures remain the same. Furthermore, thread-safety of the
1524
- interface is not affected by this option; const methods remain safe to
1525
- call from multiple threads concurrently, while non-const methods continue
1526
- to require exclusive access.
1527
-
1528
- Note that implementations may choose not to check required fields within
1529
- a lazy sub-message. That is, calling IsInitialized() on the outer message
1530
- may return true even if the inner message has missing required fields.
1531
- This is necessary because otherwise the inner message would have to be
1532
- parsed in order to perform the check, defeating the purpose of lazy
1533
- parsing. An implementation which chooses not to check required fields
1534
- must be consistent about it. That is, for any particular sub-message, the
1535
- implementation must either *always* check its required fields, or *never*
1536
- check its required fields, regardless of whether or not the message has
1537
- been parsed.
1538
- """
1539
-
1540
- deprecated: bool = betterproto2.bool_field(3)
1541
- """
1542
- Is this field deprecated?
1543
- Depending on the target platform, this can emit Deprecated annotations
1544
- for accessors, or it will be completely ignored; in the very least, this
1545
- is a formalization for deprecating fields.
1546
- """
1547
-
1548
- weak: bool = betterproto2.bool_field(10)
1549
- """For Google-internal migration only. Do not use."""
1550
-
1551
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1552
- """The parser stores options it doesn't recognize here. See above."""
1553
-
1554
-
1555
- @dataclass(eq=False, repr=False)
1556
- class OneofOptions(betterproto2.Message):
1557
- """ """
1558
-
1559
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1560
- """The parser stores options it doesn't recognize here. See above."""
1561
-
1562
-
1563
- @dataclass(eq=False, repr=False)
1564
- class EnumOptions(betterproto2.Message):
1565
- """ """
1566
-
1567
- allow_alias: bool = betterproto2.bool_field(2)
1568
- """
1569
- Set this option to true to allow mapping different tag names to the same
1570
- value.
1571
- """
1572
-
1573
- deprecated: bool = betterproto2.bool_field(3)
1574
- """
1575
- Is this enum deprecated?
1576
- Depending on the target platform, this can emit Deprecated annotations
1577
- for the enum, or it will be completely ignored; in the very least, this
1578
- is a formalization for deprecating enums.
1579
- """
1580
-
1581
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1582
- """The parser stores options it doesn't recognize here. See above."""
1583
-
1584
-
1585
- @dataclass(eq=False, repr=False)
1586
- class EnumValueOptions(betterproto2.Message):
1587
- """ """
1588
-
1589
- deprecated: bool = betterproto2.bool_field(1)
1590
- """
1591
- Is this enum value deprecated?
1592
- Depending on the target platform, this can emit Deprecated annotations
1593
- for the enum value, or it will be completely ignored; in the very least,
1594
- this is a formalization for deprecating enum values.
1595
- """
1596
-
1597
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1598
- """The parser stores options it doesn't recognize here. See above."""
1599
-
1600
-
1601
- @dataclass(eq=False, repr=False)
1602
- class ServiceOptions(betterproto2.Message):
1603
- """ """
1604
-
1605
- deprecated: bool = betterproto2.bool_field(33)
1606
- """
1607
- Note: Field numbers 1 through 32 are reserved for Google's internal RPC
1608
- framework. We apologize for hoarding these numbers to ourselves, but
1609
- we were already using them long before we decided to release Protocol
1610
- Buffers.
1611
-
1612
- Is this service deprecated?
1613
- Depending on the target platform, this can emit Deprecated annotations
1614
- for the service, or it will be completely ignored; in the very least,
1615
- this is a formalization for deprecating services.
1616
- """
1617
-
1618
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1619
- """The parser stores options it doesn't recognize here. See above."""
1620
-
1621
-
1622
- @dataclass(eq=False, repr=False)
1623
- class MethodOptions(betterproto2.Message):
1624
- """ """
1625
-
1626
- deprecated: bool = betterproto2.bool_field(33)
1627
- """
1628
- Note: Field numbers 1 through 32 are reserved for Google's internal RPC
1629
- framework. We apologize for hoarding these numbers to ourselves, but
1630
- we were already using them long before we decided to release Protocol
1631
- Buffers.
1632
-
1633
- Is this method deprecated?
1634
- Depending on the target platform, this can emit Deprecated annotations
1635
- for the method, or it will be completely ignored; in the very least,
1636
- this is a formalization for deprecating methods.
1637
- """
1638
-
1639
- idempotency_level: "MethodOptionsIdempotencyLevel" = betterproto2.enum_field(
1640
- 34, enum_default_value=lambda: MethodOptionsIdempotencyLevel.try_value(0)
1641
- )
1642
- """
1643
-
1644
- """
1645
-
1646
- uninterpreted_option: List["UninterpretedOption"] = betterproto2.message_field(999, repeated=True)
1647
- """The parser stores options it doesn't recognize here. See above."""
1648
-
1649
-
1650
- @dataclass(eq=False, repr=False)
1651
- class UninterpretedOption(betterproto2.Message):
1652
- """
1653
- A message representing a option the parser does not recognize. This only
1654
- appears in options protos created by the compiler::Parser class.
1655
- DescriptorPool resolves these when building Descriptor objects. Therefore,
1656
- options protos in descriptor objects (e.g. returned by Descriptor::options(),
1657
- or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
1658
- in them.
1659
- """
1660
-
1661
- name: List["UninterpretedOptionNamePart"] = betterproto2.message_field(2, repeated=True)
1662
- """
1663
-
1664
- """
1665
-
1666
- identifier_value: str = betterproto2.string_field(3)
1667
- """
1668
- The value of the uninterpreted option, in whatever type the tokenizer
1669
- identified it as during parsing. Exactly one of these should be set.
1670
- """
1671
-
1672
- positive_int_value: int = betterproto2.uint64_field(4)
1673
- """
1674
-
1675
- """
1676
-
1677
- negative_int_value: int = betterproto2.int64_field(5)
1678
- """
1679
-
1680
- """
1681
-
1682
- double_value: float = betterproto2.double_field(6)
1683
- """
1684
-
1685
- """
1686
-
1687
- string_value: bytes = betterproto2.bytes_field(7)
1688
- """
1689
-
1690
- """
1691
-
1692
- aggregate_value: str = betterproto2.string_field(8)
1693
- """
1694
-
1695
- """
1696
-
1697
-
1698
- @dataclass(eq=False, repr=False)
1699
- class UninterpretedOptionNamePart(betterproto2.Message):
1700
- """
1701
- The name of the uninterpreted option. Each string represents a segment in
1702
- a dot-separated name. is_extension is true iff a segment represents an
1703
- extension (denoted with parentheses in options specs in .proto files).
1704
- E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
1705
- "foo.(bar.baz).qux".
1706
- """
1707
-
1708
- name_part: str = betterproto2.string_field(1)
1709
- """
1710
-
1711
- """
1712
-
1713
- is_extension: bool = betterproto2.bool_field(2)
1714
- """
1715
-
1716
- """
1717
-
1718
-
1719
- @dataclass(eq=False, repr=False)
1720
- class SourceCodeInfo(betterproto2.Message):
1721
- """
1722
- ===================================================================
1723
- Optional source code info
1724
-
1725
- Encapsulates information about the original source file from which a
1726
- FileDescriptorProto was generated.
1727
- """
1728
-
1729
- location: List["SourceCodeInfoLocation"] = betterproto2.message_field(1, repeated=True)
1730
- """
1731
- A Location identifies a piece of source code in a .proto file which
1732
- corresponds to a particular definition. This information is intended
1733
- to be useful to IDEs, code indexers, documentation generators, and similar
1734
- tools.
1735
-
1736
- For example, say we have a file like:
1737
- message Foo {
1738
- optional string foo = 1;
1739
- }
1740
- Let's look at just the field definition:
1741
- optional string foo = 1;
1742
- ^ ^^ ^^ ^ ^^^
1743
- a bc de f ghi
1744
- We have the following locations:
1745
- span path represents
1746
- [a,i) [ 4, 0, 2, 0 ] The whole field definition.
1747
- [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
1748
- [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
1749
- [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
1750
- [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
1751
-
1752
- Notes:
1753
- - A location may refer to a repeated field itself (i.e. not to any
1754
- particular index within it). This is used whenever a set of elements are
1755
- logically enclosed in a single code segment. For example, an entire
1756
- extend block (possibly containing multiple extension definitions) will
1757
- have an outer location whose path refers to the "extensions" repeated
1758
- field without an index.
1759
- - Multiple locations may have the same path. This happens when a single
1760
- logical declaration is spread out across multiple places. The most
1761
- obvious example is the "extend" block again -- there may be multiple
1762
- extend blocks in the same scope, each of which will have the same path.
1763
- - A location's span is not always a subset of its parent's span. For
1764
- example, the "extendee" of an extension declaration appears at the
1765
- beginning of the "extend" block and is shared by all extensions within
1766
- the block.
1767
- - Just because a location's span is a subset of some other location's span
1768
- does not mean that it is a descendant. For example, a "group" defines
1769
- both a type and a field in a single declaration. Thus, the locations
1770
- corresponding to the type and field and their components will overlap.
1771
- - Code which tries to interpret locations should probably be designed to
1772
- ignore those that it doesn't understand, as more types of locations could
1773
- be recorded in the future.
1774
- """
1775
-
1776
-
1777
- @dataclass(eq=False, repr=False)
1778
- class SourceCodeInfoLocation(betterproto2.Message):
1779
- """ """
1780
-
1781
- path: List[int] = betterproto2.int32_field(1, repeated=True)
1782
- """
1783
- Identifies which part of the FileDescriptorProto was defined at this
1784
- location.
1785
-
1786
- Each element is a field number or an index. They form a path from
1787
- the root FileDescriptorProto to the place where the definition. For
1788
- example, this path:
1789
- [ 4, 3, 2, 7, 1 ]
1790
- refers to:
1791
- file.message_type(3) // 4, 3
1792
- .field(7) // 2, 7
1793
- .name() // 1
1794
- This is because FileDescriptorProto.message_type has field number 4:
1795
- repeated DescriptorProto message_type = 4;
1796
- and DescriptorProto.field has field number 2:
1797
- repeated FieldDescriptorProto field = 2;
1798
- and FieldDescriptorProto.name has field number 1:
1799
- optional string name = 1;
1800
-
1801
- Thus, the above path gives the location of a field name. If we removed
1802
- the last element:
1803
- [ 4, 3, 2, 7 ]
1804
- this path refers to the whole field declaration (from the beginning
1805
- of the label to the terminating semicolon).
1806
- """
1807
-
1808
- span: List[int] = betterproto2.int32_field(2, repeated=True)
1809
- """
1810
- Always has exactly three or four elements: start line, start column,
1811
- end line (optional, otherwise assumed same as start line), end column.
1812
- These are packed into a single field for efficiency. Note that line
1813
- and column numbers are zero-based -- typically you will want to add
1814
- 1 to each before displaying to a user.
1815
- """
1816
-
1817
- leading_comments: str = betterproto2.string_field(3)
1818
- """
1819
- If this SourceCodeInfo represents a complete declaration, these are any
1820
- comments appearing before and after the declaration which appear to be
1821
- attached to the declaration.
1822
-
1823
- A series of line comments appearing on consecutive lines, with no other
1824
- tokens appearing on those lines, will be treated as a single comment.
1825
-
1826
- leading_detached_comments will keep paragraphs of comments that appear
1827
- before (but not connected to) the current element. Each paragraph,
1828
- separated by empty lines, will be one comment element in the repeated
1829
- field.
1830
-
1831
- Only the comment content is provided; comment markers (e.g. //) are
1832
- stripped out. For block comments, leading whitespace and an asterisk
1833
- will be stripped from the beginning of each line other than the first.
1834
- Newlines are included in the output.
1835
-
1836
- Examples:
1837
-
1838
- optional int32 foo = 1; // Comment attached to foo.
1839
- // Comment attached to bar.
1840
- optional int32 bar = 2;
1841
-
1842
- optional string baz = 3;
1843
- // Comment attached to baz.
1844
- // Another line attached to baz.
1845
-
1846
- // Comment attached to qux.
1847
- //
1848
- // Another line attached to qux.
1849
- optional double qux = 4;
1850
-
1851
- // Detached comment for corge. This is not leading or trailing comments
1852
- // to qux or corge because there are blank lines separating it from
1853
- // both.
1854
-
1855
- // Detached comment for corge paragraph 2.
1856
-
1857
- optional string corge = 5;
1858
- /* Block comment attached
1859
- * to corge. Leading asterisks
1860
- * will be removed. */
1861
- /* Block comment attached to
1862
- * grault. */
1863
- optional int32 grault = 6;
1864
-
1865
- // ignored detached comments.
1866
- """
1867
-
1868
- trailing_comments: str = betterproto2.string_field(4)
1869
- """
1870
-
1871
- """
1872
-
1873
- leading_detached_comments: List[str] = betterproto2.string_field(6, repeated=True)
1874
- """
1875
-
1876
- """
1877
-
1878
-
1879
- @dataclass(eq=False, repr=False)
1880
- class GeneratedCodeInfo(betterproto2.Message):
1881
- """
1882
- Describes the relationship between generated code and its original source
1883
- file. A GeneratedCodeInfo message is associated with only one generated
1884
- source file, but may contain references to different source .proto files.
1885
- """
1886
-
1887
- annotation: List["GeneratedCodeInfoAnnotation"] = betterproto2.message_field(1, repeated=True)
1888
- """
1889
- An Annotation connects some span of text in generated code to an element
1890
- of its generating .proto file.
1891
- """
1892
-
1893
-
1894
- @dataclass(eq=False, repr=False)
1895
- class GeneratedCodeInfoAnnotation(betterproto2.Message):
1896
- """ """
1897
-
1898
- path: List[int] = betterproto2.int32_field(1, repeated=True)
1899
- """
1900
- Identifies the element in the original source .proto file. This field
1901
- is formatted the same as SourceCodeInfo.Location.path.
1902
- """
1903
-
1904
- source_file: str = betterproto2.string_field(2)
1905
- """Identifies the filesystem path to the original source .proto."""
1906
-
1907
- begin: int = betterproto2.int32_field(3)
1908
- """
1909
- Identifies the starting offset in bytes in the generated code
1910
- that relates to the identified object.
1911
- """
1912
-
1913
- end: int = betterproto2.int32_field(4)
1914
- """
1915
- Identifies the ending offset in bytes in the generated code that
1916
- relates to the identified offset. The end offset should be one past
1917
- the last relevant byte (so the length of the text = end - begin).
1918
- """
1919
-
1920
-
1921
- @dataclass(eq=False, repr=False)
1922
- class Duration(betterproto2.Message):
1923
- """
1924
- A Duration represents a signed, fixed-length span of time represented
1925
- as a count of seconds and fractions of seconds at nanosecond
1926
- resolution. It is independent of any calendar and concepts like "day"
1927
- or "month". It is related to Timestamp in that the difference between
1928
- two Timestamp values is a Duration and it can be added or subtracted
1929
- from a Timestamp. Range is approximately +-10,000 years.
1930
-
1931
- # Examples
1932
-
1933
- Example 1: Compute Duration from two Timestamps in pseudo code.
1934
-
1935
- Timestamp start = ...;
1936
- Timestamp end = ...;
1937
- Duration duration = ...;
1938
-
1939
- duration.seconds = end.seconds - start.seconds;
1940
- duration.nanos = end.nanos - start.nanos;
1941
-
1942
- if (duration.seconds < 0 && duration.nanos > 0) {
1943
- duration.seconds += 1;
1944
- duration.nanos -= 1000000000;
1945
- } else if (duration.seconds > 0 && duration.nanos < 0) {
1946
- duration.seconds -= 1;
1947
- duration.nanos += 1000000000;
1948
- }
1949
-
1950
- Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
1951
-
1952
- Timestamp start = ...;
1953
- Duration duration = ...;
1954
- Timestamp end = ...;
1955
-
1956
- end.seconds = start.seconds + duration.seconds;
1957
- end.nanos = start.nanos + duration.nanos;
1958
-
1959
- if (end.nanos < 0) {
1960
- end.seconds -= 1;
1961
- end.nanos += 1000000000;
1962
- } else if (end.nanos >= 1000000000) {
1963
- end.seconds += 1;
1964
- end.nanos -= 1000000000;
1965
- }
1966
-
1967
- Example 3: Compute Duration from datetime.timedelta in Python.
1968
-
1969
- td = datetime.timedelta(days=3, minutes=10)
1970
- duration = Duration()
1971
- duration.FromTimedelta(td)
1972
-
1973
- # JSON Mapping
1974
-
1975
- In JSON format, the Duration type is encoded as a string rather than an
1976
- object, where the string ends in the suffix "s" (indicating seconds) and
1977
- is preceded by the number of seconds, with nanoseconds expressed as
1978
- fractional seconds. For example, 3 seconds with 0 nanoseconds should be
1979
- encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
1980
- be expressed in JSON format as "3.000000001s", and 3 seconds and 1
1981
- microsecond should be expressed in JSON format as "3.000001s".
1982
- """
1983
-
1984
- seconds: int = betterproto2.int64_field(1)
1985
- """
1986
- Signed seconds of the span of time. Must be from -315,576,000,000
1987
- to +315,576,000,000 inclusive. Note: these bounds are computed from:
1988
- 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
1989
- """
1990
-
1991
- nanos: int = betterproto2.int32_field(2)
1992
- """
1993
- Signed fractions of a second at nanosecond resolution of the span
1994
- of time. Durations less than one second are represented with a 0
1995
- `seconds` field and a positive or negative `nanos` field. For durations
1996
- of one second or more, a non-zero value for the `nanos` field must be
1997
- of the same sign as the `seconds` field. Must be from -999,999,999
1998
- to +999,999,999 inclusive.
1999
- """
2000
-
2001
-
2002
- @dataclass(eq=False, repr=False)
2003
- class Empty(betterproto2.Message):
2004
- """
2005
- A generic empty message that you can re-use to avoid defining duplicated
2006
- empty messages in your APIs. A typical example is to use it as the request
2007
- or the response type of an API method. For instance:
2008
-
2009
- service Foo {
2010
- rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
2011
- }
2012
-
2013
- The JSON representation for `Empty` is empty JSON object `{}`.
2014
- """
2015
-
2016
- pass
2017
-
2018
-
2019
- @dataclass(eq=False, repr=False)
2020
- class FieldMask(betterproto2.Message):
2021
- """
2022
- `FieldMask` represents a set of symbolic field paths, for example:
2023
-
2024
- paths: "f.a"
2025
- paths: "f.b.d"
2026
-
2027
- Here `f` represents a field in some root message, `a` and `b`
2028
- fields in the message found in `f`, and `d` a field found in the
2029
- message in `f.b`.
2030
-
2031
- Field masks are used to specify a subset of fields that should be
2032
- returned by a get operation or modified by an update operation.
2033
- Field masks also have a custom JSON encoding (see below).
2034
-
2035
- # Field Masks in Projections
2036
-
2037
- When used in the context of a projection, a response message or
2038
- sub-message is filtered by the API to only contain those fields as
2039
- specified in the mask. For example, if the mask in the previous
2040
- example is applied to a response message as follows:
2041
-
2042
- f {
2043
- a : 22
2044
- b {
2045
- d : 1
2046
- x : 2
2047
- }
2048
- y : 13
2049
- }
2050
- z: 8
2051
-
2052
- The result will not contain specific values for fields x,y and z
2053
- (their value will be set to the default, and omitted in proto text
2054
- output):
2055
-
2056
- f {
2057
- a : 22
2058
- b {
2059
- d : 1
2060
- }
2061
- }
2062
-
2063
- A repeated field is not allowed except at the last position of a
2064
- paths string.
2065
-
2066
- If a FieldMask object is not present in a get operation, the
2067
- operation applies to all fields (as if a FieldMask of all fields
2068
- had been specified).
2069
-
2070
- Note that a field mask does not necessarily apply to the
2071
- top-level response message. In case of a REST get operation, the
2072
- field mask applies directly to the response, but in case of a REST
2073
- list operation, the mask instead applies to each individual message
2074
- in the returned resource list. In case of a REST custom method,
2075
- other definitions may be used. Where the mask applies will be
2076
- clearly documented together with its declaration in the API. In
2077
- any case, the effect on the returned resource/resources is required
2078
- behavior for APIs.
2079
-
2080
- # Field Masks in Update Operations
2081
-
2082
- A field mask in update operations specifies which fields of the
2083
- targeted resource are going to be updated. The API is required
2084
- to only change the values of the fields as specified in the mask
2085
- and leave the others untouched. If a resource is passed in to
2086
- describe the updated values, the API ignores the values of all
2087
- fields not covered by the mask.
2088
-
2089
- If a repeated field is specified for an update operation, new values will
2090
- be appended to the existing repeated field in the target resource. Note that
2091
- a repeated field is only allowed in the last position of a `paths` string.
2092
-
2093
- If a sub-message is specified in the last position of the field mask for an
2094
- update operation, then new value will be merged into the existing sub-message
2095
- in the target resource.
2096
-
2097
- For example, given the target message:
2098
-
2099
- f {
2100
- b {
2101
- d: 1
2102
- x: 2
2103
- }
2104
- c: [1]
2105
- }
2106
-
2107
- And an update message:
2108
-
2109
- f {
2110
- b {
2111
- d: 10
2112
- }
2113
- c: [2]
2114
- }
2115
-
2116
- then if the field mask is:
2117
-
2118
- paths: ["f.b", "f.c"]
2119
-
2120
- then the result will be:
2121
-
2122
- f {
2123
- b {
2124
- d: 10
2125
- x: 2
2126
- }
2127
- c: [1, 2]
2128
- }
2129
-
2130
- An implementation may provide options to override this default behavior for
2131
- repeated and message fields.
2132
-
2133
- In order to reset a field's value to the default, the field must
2134
- be in the mask and set to the default value in the provided resource.
2135
- Hence, in order to reset all fields of a resource, provide a default
2136
- instance of the resource and set all fields in the mask, or do
2137
- not provide a mask as described below.
2138
-
2139
- If a field mask is not present on update, the operation applies to
2140
- all fields (as if a field mask of all fields has been specified).
2141
- Note that in the presence of schema evolution, this may mean that
2142
- fields the client does not know and has therefore not filled into
2143
- the request will be reset to their default. If this is unwanted
2144
- behavior, a specific service may require a client to always specify
2145
- a field mask, producing an error if not.
2146
-
2147
- As with get operations, the location of the resource which
2148
- describes the updated values in the request message depends on the
2149
- operation kind. In any case, the effect of the field mask is
2150
- required to be honored by the API.
2151
-
2152
- ## Considerations for HTTP REST
2153
-
2154
- The HTTP kind of an update operation which uses a field mask must
2155
- be set to PATCH instead of PUT in order to satisfy HTTP semantics
2156
- (PUT must only be used for full updates).
2157
-
2158
- # JSON Encoding of Field Masks
2159
-
2160
- In JSON, a field mask is encoded as a single string where paths are
2161
- separated by a comma. Fields name in each path are converted
2162
- to/from lower-camel naming conventions.
2163
-
2164
- As an example, consider the following message declarations:
2165
-
2166
- message Profile {
2167
- User user = 1;
2168
- Photo photo = 2;
2169
- }
2170
- message User {
2171
- string display_name = 1;
2172
- string address = 2;
2173
- }
2174
-
2175
- In proto a field mask for `Profile` may look as such:
2176
-
2177
- mask {
2178
- paths: "user.display_name"
2179
- paths: "photo"
2180
- }
2181
-
2182
- In JSON, the same mask is represented as below:
2183
-
2184
- {
2185
- mask: "user.displayName,photo"
2186
- }
2187
-
2188
- # Field Masks and Oneof Fields
2189
-
2190
- Field masks treat fields in oneofs just as regular fields. Consider the
2191
- following message:
2192
-
2193
- message SampleMessage {
2194
- oneof test_oneof {
2195
- string name = 4;
2196
- SubMessage sub_message = 9;
2197
- }
2198
- }
2199
-
2200
- The field mask can be:
2201
-
2202
- mask {
2203
- paths: "name"
2204
- }
2205
-
2206
- Or:
2207
-
2208
- mask {
2209
- paths: "sub_message"
2210
- }
2211
-
2212
- Note that oneof type names ("test_oneof" in this case) cannot be used in
2213
- paths.
2214
-
2215
- ## Field Mask Verification
2216
-
2217
- The implementation of any API method which has a FieldMask type field in the
2218
- request should verify the included field paths, and return an
2219
- `INVALID_ARGUMENT` error if any path is unmappable.
2220
- """
2221
-
2222
- paths: List[str] = betterproto2.string_field(1, repeated=True)
2223
- """The set of field mask paths."""
2224
-
2225
-
2226
- @dataclass(eq=False, repr=False)
2227
- class Struct(betterproto2.Message):
2228
- """
2229
- `Struct` represents a structured data value, consisting of fields
2230
- which map to dynamically typed values. In some languages, `Struct`
2231
- might be supported by a native representation. For example, in
2232
- scripting languages like JS a struct is represented as an
2233
- object. The details of that representation are described together
2234
- with the proto support for the language.
2235
-
2236
- The JSON representation for `Struct` is JSON object.
2237
- """
2238
-
2239
- fields: Dict[str, "Value"] = betterproto2.map_field(1, betterproto2.TYPE_STRING, betterproto2.TYPE_MESSAGE)
2240
- """Unordered map of dynamically typed values."""
2241
-
2242
- @hybridmethod
2243
- def from_dict(cls: "type[Self]", value: Mapping[str, Any]) -> Self: # type: ignore
2244
- self = cls()
2245
- return self.from_dict(value)
2246
-
2247
- @from_dict.instancemethod
2248
- def from_dict(self, value: Mapping[str, Any]) -> Self:
2249
- fields = {**value}
2250
- for k in fields:
2251
- if hasattr(fields[k], "from_dict"):
2252
- fields[k] = fields[k].from_dict()
2253
-
2254
- self.fields = fields
2255
- return self
2256
-
2257
- def to_dict(
2258
- self,
2259
- casing: betterproto2.Casing = betterproto2.Casing.CAMEL,
2260
- include_default_values: bool = False,
2261
- ) -> Dict[str, Any]:
2262
- output = {**self.fields}
2263
- for k in self.fields:
2264
- if hasattr(self.fields[k], "to_dict"):
2265
- output[k] = self.fields[k].to_dict(casing, include_default_values)
2266
- return output
2267
-
2268
-
2269
- @dataclass(eq=False, repr=False)
2270
- class Value(betterproto2.Message):
2271
- """
2272
- `Value` represents a dynamically typed value which can be either
2273
- null, a number, a string, a boolean, a recursive struct value, or a
2274
- list of values. A producer of value is expected to set one of that
2275
- variants, absence of any variant indicates an error.
2276
-
2277
- The JSON representation for `Value` is JSON value.
2278
- """
2279
-
2280
- null_value: "NullValue" = betterproto2.enum_field(
2281
- 1, enum_default_value=lambda: NullValue.try_value(0), group="kind"
2282
- )
2283
- """Represents a null value."""
2284
-
2285
- number_value: float = betterproto2.double_field(2, group="kind")
2286
- """Represents a double value."""
2287
-
2288
- string_value: str = betterproto2.string_field(3, group="kind")
2289
- """Represents a string value."""
2290
-
2291
- bool_value: bool = betterproto2.bool_field(4, group="kind")
2292
- """Represents a boolean value."""
2293
-
2294
- struct_value: "Struct" = betterproto2.message_field(5, group="kind")
2295
- """Represents a structured value."""
2296
-
2297
- list_value: "ListValue" = betterproto2.message_field(6, group="kind")
2298
- """Represents a repeated `Value`."""
2299
-
2300
-
2301
- @dataclass(eq=False, repr=False)
2302
- class ListValue(betterproto2.Message):
2303
- """
2304
- `ListValue` is a wrapper around a repeated field of values.
2305
-
2306
- The JSON representation for `ListValue` is JSON array.
2307
- """
2308
-
2309
- values: List["Value"] = betterproto2.message_field(1, repeated=True)
2310
- """Repeated field of dynamically typed values."""
2311
-
2312
-
2313
- @dataclass(eq=False, repr=False)
2314
- class Timestamp(betterproto2.Message):
2315
- """
2316
- A Timestamp represents a point in time independent of any time zone or local
2317
- calendar, encoded as a count of seconds and fractions of seconds at
2318
- nanosecond resolution. The count is relative to an epoch at UTC midnight on
2319
- January 1, 1970, in the proleptic Gregorian calendar which extends the
2320
- Gregorian calendar backwards to year one.
2321
-
2322
- All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
2323
- second table is needed for interpretation, using a [24-hour linear
2324
- smear](https://developers.google.com/time/smear).
2325
-
2326
- The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
2327
- restricting to that range, we ensure that we can convert to and from [RFC
2328
- 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
2329
-
2330
- # Examples
2331
-
2332
- Example 1: Compute Timestamp from POSIX `time()`.
2333
-
2334
- Timestamp timestamp;
2335
- timestamp.set_seconds(time(NULL));
2336
- timestamp.set_nanos(0);
2337
-
2338
- Example 2: Compute Timestamp from POSIX `gettimeofday()`.
2339
-
2340
- struct timeval tv;
2341
- gettimeofday(&tv, NULL);
2342
-
2343
- Timestamp timestamp;
2344
- timestamp.set_seconds(tv.tv_sec);
2345
- timestamp.set_nanos(tv.tv_usec * 1000);
2346
-
2347
- Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
2348
-
2349
- FILETIME ft;
2350
- GetSystemTimeAsFileTime(&ft);
2351
- UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
2352
-
2353
- // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
2354
- // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
2355
- Timestamp timestamp;
2356
- timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
2357
- timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
2358
-
2359
- Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
2360
-
2361
- long millis = System.currentTimeMillis();
2362
-
2363
- Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
2364
- .setNanos((int) ((millis % 1000) * 1000000)).build();
2365
-
2366
- Example 5: Compute Timestamp from current time in Python.
2367
-
2368
- timestamp = Timestamp()
2369
- timestamp.GetCurrentTime()
2370
-
2371
- # JSON Mapping
2372
-
2373
- In JSON format, the Timestamp type is encoded as a string in the
2374
- [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
2375
- format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
2376
- where {year} is always expressed using four digits while {month}, {day},
2377
- {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
2378
- seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
2379
- are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
2380
- is required. A proto3 JSON serializer should always use UTC (as indicated by
2381
- "Z") when printing the Timestamp type and a proto3 JSON parser should be
2382
- able to accept both UTC and other timezones (as indicated by an offset).
2383
-
2384
- For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
2385
- 01:30 UTC on January 15, 2017.
2386
-
2387
- In JavaScript, one can convert a Date object to this format using the
2388
- standard
2389
- [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
2390
- method. In Python, a standard `datetime.datetime` object can be converted
2391
- to this format using
2392
- [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
2393
- the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
2394
- the Joda Time's [`ISODateTimeFormat.dateTime()`](
2395
- http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
2396
- ) to obtain a formatter capable of generating timestamps in this format.
2397
- """
2398
-
2399
- seconds: int = betterproto2.int64_field(1)
2400
- """
2401
- Represents seconds of UTC time since Unix epoch
2402
- 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
2403
- 9999-12-31T23:59:59Z inclusive.
2404
- """
2405
-
2406
- nanos: int = betterproto2.int32_field(2)
2407
- """
2408
- Non-negative fractions of a second at nanosecond resolution. Negative
2409
- second values with fractions must still have non-negative nanos values
2410
- that count forward in time. Must be from 0 to 999,999,999
2411
- inclusive.
2412
- """
2413
-
2414
-
2415
- @dataclass(eq=False, repr=False)
2416
- class DoubleValue(betterproto2.Message):
2417
- """
2418
- Wrapper message for `double`.
2419
-
2420
- The JSON representation for `DoubleValue` is JSON number.
2421
- """
2422
-
2423
- value: float = betterproto2.double_field(1)
2424
- """The double value."""
2425
-
2426
-
2427
- @dataclass(eq=False, repr=False)
2428
- class FloatValue(betterproto2.Message):
2429
- """
2430
- Wrapper message for `float`.
2431
-
2432
- The JSON representation for `FloatValue` is JSON number.
2433
- """
2434
-
2435
- value: float = betterproto2.float_field(1)
2436
- """The float value."""
2437
-
2438
-
2439
- @dataclass(eq=False, repr=False)
2440
- class Int64Value(betterproto2.Message):
2441
- """
2442
- Wrapper message for `int64`.
2443
-
2444
- The JSON representation for `Int64Value` is JSON string.
2445
- """
2446
-
2447
- value: int = betterproto2.int64_field(1)
2448
- """The int64 value."""
2449
-
2450
-
2451
- @dataclass(eq=False, repr=False)
2452
- class UInt64Value(betterproto2.Message):
2453
- """
2454
- Wrapper message for `uint64`.
2455
-
2456
- The JSON representation for `UInt64Value` is JSON string.
2457
- """
2458
-
2459
- value: int = betterproto2.uint64_field(1)
2460
- """The uint64 value."""
2461
-
2462
-
2463
- @dataclass(eq=False, repr=False)
2464
- class Int32Value(betterproto2.Message):
2465
- """
2466
- Wrapper message for `int32`.
2467
-
2468
- The JSON representation for `Int32Value` is JSON number.
2469
- """
2470
-
2471
- value: int = betterproto2.int32_field(1)
2472
- """The int32 value."""
2473
-
2474
-
2475
- @dataclass(eq=False, repr=False)
2476
- class UInt32Value(betterproto2.Message):
2477
- """
2478
- Wrapper message for `uint32`.
2479
-
2480
- The JSON representation for `UInt32Value` is JSON number.
2481
- """
2482
-
2483
- value: int = betterproto2.uint32_field(1)
2484
- """The uint32 value."""
2485
-
2486
-
2487
- @dataclass(eq=False, repr=False)
2488
- class BoolValue(betterproto2.Message):
2489
- """
2490
- Wrapper message for `bool`.
2491
-
2492
- The JSON representation for `BoolValue` is JSON `true` and `false`.
2493
- """
2494
-
2495
- value: bool = betterproto2.bool_field(1)
2496
- """The bool value."""
2497
-
2498
-
2499
- @dataclass(eq=False, repr=False)
2500
- class StringValue(betterproto2.Message):
2501
- """
2502
- Wrapper message for `string`.
2503
-
2504
- The JSON representation for `StringValue` is JSON string.
2505
- """
2506
-
2507
- value: str = betterproto2.string_field(1)
2508
- """The string value."""
2509
-
2510
-
2511
- @dataclass(eq=False, repr=False)
2512
- class BytesValue(betterproto2.Message):
2513
- """
2514
- Wrapper message for `bytes`.
2515
-
2516
- The JSON representation for `BytesValue` is JSON string.
2517
- """
2518
-
2519
- value: bytes = betterproto2.bytes_field(1)
2520
- """The bytes value."""