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