protobug_well_known_protos 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b08ae3c504d305248dda53c7720cc562905839fd9fcbe44e1458f16ad88a429
4
+ data.tar.gz: 2659920109668e8d541e1d46cbaff2d46dfa7215e74ce0ddc086421aebc92168
5
+ SHA512:
6
+ metadata.gz: a2389d6b25c1fe80f8e75d6079cd78080e8d1e5f6f87d6b5e19b4d29b007a5c84ec24d38b2590346f180848a4571b31901d9c832a5ce8aec256088833c2d58bb
7
+ data.tar.gz: d0f5141be655c8afd89473a413a5835579a70509d66c62872e1ae6dd3db741d1e7a550b1b197a21fd461227df67d8194d4084f1dc9e8bd7e472ad78c92a6bae9
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by protoc-gen-protobug. DO NOT EDIT.
4
+
5
+ # source: google/protobuf/any.proto
6
+ # syntax: proto3
7
+ # package: google.protobuf
8
+ # options:
9
+ # java_package: "com.google.protobuf"
10
+ # java_outer_classname: "AnyProto"
11
+ # java_multiple_files: true
12
+ # go_package: "google.golang.org/protobuf/types/known/anypb"
13
+ # objc_class_prefix: "GPB"
14
+ # csharp_namespace: "Google.Protobuf.WellKnownTypes"
15
+
16
+ # Protocol Buffers - Google's data interchange format
17
+ # Copyright 2008 Google Inc. All rights reserved.
18
+ # https://developers.google.com/protocol-buffers/
19
+ #
20
+ # Redistribution and use in source and binary forms, with or without
21
+ # modification, are permitted provided that the following conditions are
22
+ # met:
23
+ #
24
+ # * Redistributions of source code must retain the above copyright
25
+ # notice, this list of conditions and the following disclaimer.
26
+ # * Redistributions in binary form must reproduce the above
27
+ # copyright notice, this list of conditions and the following disclaimer
28
+ # in the documentation and/or other materials provided with the
29
+ # distribution.
30
+ # * Neither the name of Google Inc. nor the names of its
31
+ # contributors may be used to endorse or promote products derived from
32
+ # this software without specific prior written permission.
33
+ #
34
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
+
46
+ require "protobug"
47
+
48
+ module Google
49
+ module Protobuf
50
+ # `Any` contains an arbitrary serialized protocol buffer message along with a
51
+ # URL that describes the type of the serialized message.
52
+ #
53
+ # Protobuf library provides support to pack/unpack Any values in the form
54
+ # of utility functions or additional generated methods of the Any type.
55
+ #
56
+ # Example 1: Pack and unpack a message in C++.
57
+ #
58
+ # Foo foo = ...;
59
+ # Any any;
60
+ # any.PackFrom(foo);
61
+ # ...
62
+ # if (any.UnpackTo(&foo)) {
63
+ # ...
64
+ # }
65
+ #
66
+ # Example 2: Pack and unpack a message in Java.
67
+ #
68
+ # Foo foo = ...;
69
+ # Any any = Any.pack(foo);
70
+ # ...
71
+ # if (any.is(Foo.class)) {
72
+ # foo = any.unpack(Foo.class);
73
+ # }
74
+ # // or ...
75
+ # if (any.isSameTypeAs(Foo.getDefaultInstance())) {
76
+ # foo = any.unpack(Foo.getDefaultInstance());
77
+ # }
78
+ #
79
+ # Example 3: Pack and unpack a message in Python.
80
+ #
81
+ # foo = Foo(...)
82
+ # any = Any()
83
+ # any.Pack(foo)
84
+ # ...
85
+ # if any.Is(Foo.DESCRIPTOR):
86
+ # any.Unpack(foo)
87
+ # ...
88
+ #
89
+ # Example 4: Pack and unpack a message in Go
90
+ #
91
+ # foo := &pb.Foo{...}
92
+ # any, err := anypb.New(foo)
93
+ # if err != nil {
94
+ # ...
95
+ # }
96
+ # ...
97
+ # foo := &pb.Foo{}
98
+ # if err := any.UnmarshalTo(foo); err != nil {
99
+ # ...
100
+ # }
101
+ #
102
+ # The pack methods provided by protobuf library will by default use
103
+ # 'type.googleapis.com/full.type.name' as the type URL and the unpack
104
+ # methods only use the fully qualified type name after the last '/'
105
+ # in the type URL, for example "foo.bar.com/x/y.z" will yield type
106
+ # name "y.z".
107
+ #
108
+ # JSON
109
+ # ====
110
+ # The JSON representation of an `Any` value uses the regular
111
+ # representation of the deserialized, embedded message, with an
112
+ # additional field `@type` which contains the type URL. Example:
113
+ #
114
+ # package google.profile;
115
+ # message Person {
116
+ # string first_name = 1;
117
+ # string last_name = 2;
118
+ # }
119
+ #
120
+ # {
121
+ # "@type": "type.googleapis.com/google.profile.Person",
122
+ # "firstName": <string>,
123
+ # "lastName": <string>
124
+ # }
125
+ #
126
+ # If the embedded message type is well-known and has a custom JSON
127
+ # representation, that representation will be embedded adding a field
128
+ # `value` which holds the custom JSON in addition to the `@type`
129
+ # field. Example (for message [google.protobuf.Duration][]):
130
+ #
131
+ # {
132
+ # "@type": "type.googleapis.com/google.protobuf.Duration",
133
+ # "value": "1.212s"
134
+ # }
135
+ class Any
136
+ extend Protobug::Message
137
+
138
+ self.full_name = "google.protobuf.Any"
139
+
140
+ # A URL/resource name that uniquely identifies the type of the serialized
141
+ # protocol buffer message. This string must contain at least
142
+ # one "/" character. The last segment of the URL's path must represent
143
+ # the fully qualified name of the type (as in
144
+ # `path/google.protobuf.Duration`). The name should be in a canonical form
145
+ # (e.g., leading "." is not accepted).
146
+ #
147
+ # In practice, teams usually precompile into the binary all types that they
148
+ # expect it to use in the context of Any. However, for URLs which use the
149
+ # scheme `http`, `https`, or no scheme, one can optionally set up a type
150
+ # server that maps type URLs to message definitions as follows:
151
+ #
152
+ # * If no scheme is provided, `https` is assumed.
153
+ # * An HTTP GET on the URL must yield a [google.protobuf.Type][]
154
+ # value in binary format, or produce an error.
155
+ # * Applications are allowed to cache lookup results based on the
156
+ # URL, or have them precompiled into a binary to avoid any
157
+ # lookup. Therefore, binary compatibility needs to be preserved
158
+ # on changes to types. (Use versioned type names to manage
159
+ # breaking changes.)
160
+ #
161
+ # Note: this functionality is not currently available in the official
162
+ # protobuf release, and it is not used for type URLs beginning with
163
+ # type.googleapis.com. As of May 2023, there are no widely used type server
164
+ # implementations and no plans to implement one.
165
+ #
166
+ # Schemes other than `http`, `https` (or the empty scheme) might be
167
+ # used with implementation specific semantics.
168
+ optional(
169
+ 1,
170
+ "type_url",
171
+ type: :string,
172
+ json_name: "typeUrl",
173
+ proto3_optional: false
174
+ )
175
+ # Must be a valid serialized protocol buffer of the above specified type.
176
+ optional(2, "value", type: :bytes, proto3_optional: false)
177
+ end
178
+
179
+ def self.register_any_protos(registry)
180
+ registry.register(Google::Protobuf::Any)
181
+ end
182
+ end
183
+ end
184
+
185
+ require_relative "any_well_known"
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ Google::Protobuf::Any.class_eval do
4
+ def self.pack(msg)
5
+ any = new
6
+ any.pack(msg)
7
+ any
8
+ end
9
+
10
+ def pack(msg)
11
+ self.type_url = "type.googleapis.com/#{msg.class.full_name}"
12
+ self.value = msg.to_proto
13
+ end
14
+
15
+ def unpack(registry)
16
+ type = registry.fetch(type_url.delete_prefix("type.googleapis.com/"))
17
+ type.decode(value, registry: registry)
18
+ end
19
+
20
+ def self.decode_json_hash(json, registry:, ignore_unknown_fields: false)
21
+ raise Protobug::DecodeError, "expected hash, got #{json.inspect}" unless json.is_a? Hash
22
+
23
+ json = json.dup
24
+ type_url = json.delete("@type") || raise(Protobug::DecodeError, "missing @type")
25
+ raise Protobug::DecodeError, "expected string for @type, got #{type_url.inspect}" unless type_url.is_a? String
26
+
27
+ unless type_url.start_with?("type.googleapis.com/")
28
+ raise Protobug::DecodeError, "only type.googleapis.com/ types are supported for Any"
29
+ end
30
+
31
+ # TODO: specifically check for well-known type with custom JSON representation
32
+ json = json["value"] if json.key?("value") && json.size == 1
33
+
34
+ type = registry.fetch(type_url.delete_prefix("type.googleapis.com/"))
35
+ v = type.decode_json_hash(json, registry: registry, ignore_unknown_fields: ignore_unknown_fields)
36
+ json = {
37
+ "type_url" => type_url,
38
+ "value" => [type.encode(v)].pack("m0")
39
+ }
40
+ super
41
+ end
42
+
43
+ def as_json(print_unknown_fields: false) # rubocop:disable Lint/UnusedMethodArgument
44
+ # TODO: need a registry to look up the type
45
+ raise Protobug::UnsupportedFeatureError.new(:any, "serializing to json")
46
+ # return value.as_json.merge("@type" => "type.googleapis.com/#{value.class.full_name}")
47
+ end
48
+ end
@@ -0,0 +1,286 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by protoc-gen-protobug. DO NOT EDIT.
4
+
5
+ # source: google/protobuf/api.proto
6
+ # syntax: proto3
7
+ # package: google.protobuf
8
+ # options:
9
+ # java_package: "com.google.protobuf"
10
+ # java_outer_classname: "ApiProto"
11
+ # java_multiple_files: true
12
+ # go_package: "google.golang.org/protobuf/types/known/apipb"
13
+ # objc_class_prefix: "GPB"
14
+ # csharp_namespace: "Google.Protobuf.WellKnownTypes"
15
+
16
+ # Protocol Buffers - Google's data interchange format
17
+ # Copyright 2008 Google Inc. All rights reserved.
18
+ # https://developers.google.com/protocol-buffers/
19
+ #
20
+ # Redistribution and use in source and binary forms, with or without
21
+ # modification, are permitted provided that the following conditions are
22
+ # met:
23
+ #
24
+ # * Redistributions of source code must retain the above copyright
25
+ # notice, this list of conditions and the following disclaimer.
26
+ # * Redistributions in binary form must reproduce the above
27
+ # copyright notice, this list of conditions and the following disclaimer
28
+ # in the documentation and/or other materials provided with the
29
+ # distribution.
30
+ # * Neither the name of Google Inc. nor the names of its
31
+ # contributors may be used to endorse or promote products derived from
32
+ # this software without specific prior written permission.
33
+ #
34
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42
+ # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
+
46
+ require "protobug"
47
+
48
+ require_relative "source_context_pb"
49
+ require_relative "type_pb"
50
+
51
+ module Google
52
+ module Protobuf
53
+ # Api is a light-weight descriptor for an API Interface.
54
+ #
55
+ # Interfaces are also described as "protocol buffer services" in some contexts,
56
+ # such as by the "service" keyword in a .proto file, but they are different
57
+ # from API Services, which represent a concrete implementation of an interface
58
+ # as opposed to simply a description of methods and bindings. They are also
59
+ # sometimes simply referred to as "APIs" in other contexts, such as the name of
60
+ # this message itself. See https://cloud.google.com/apis/design/glossary for
61
+ # detailed terminology.
62
+ class Api
63
+ extend Protobug::Message
64
+
65
+ self.full_name = "google.protobuf.Api"
66
+
67
+ # The fully qualified name of this interface, including package name
68
+ # followed by the interface's simple name.
69
+ optional(1, "name", type: :string, proto3_optional: false)
70
+ # The methods of this interface, in unspecified order.
71
+ repeated(
72
+ 2,
73
+ "methods",
74
+ type: :message,
75
+ message_type: "google.protobuf.Method"
76
+ )
77
+ # Any metadata attached to the interface.
78
+ repeated(
79
+ 3,
80
+ "options",
81
+ type: :message,
82
+ message_type: "google.protobuf.Option"
83
+ )
84
+ # A version string for this interface. If specified, must have the form
85
+ # `major-version.minor-version`, as in `1.10`. If the minor version is
86
+ # omitted, it defaults to zero. If the entire version field is empty, the
87
+ # major version is derived from the package name, as outlined below. If the
88
+ # field is not empty, the version in the package name will be verified to be
89
+ # consistent with what is provided here.
90
+ #
91
+ # The versioning schema uses [semantic
92
+ # versioning](http://semver.org) where the major version number
93
+ # indicates a breaking change and the minor version an additive,
94
+ # non-breaking change. Both version numbers are signals to users
95
+ # what to expect from different versions, and should be carefully
96
+ # chosen based on the product plan.
97
+ #
98
+ # The major version is also reflected in the package name of the
99
+ # interface, which must end in `v<major-version>`, as in
100
+ # `google.feature.v1`. For major versions 0 and 1, the suffix can
101
+ # be omitted. Zero major versions must only be used for
102
+ # experimental, non-GA interfaces.
103
+ optional(4, "version", type: :string, proto3_optional: false)
104
+ # Source context for the protocol buffer service represented by this
105
+ # message.
106
+ optional(
107
+ 5,
108
+ "source_context",
109
+ type: :message,
110
+ message_type: "google.protobuf.SourceContext",
111
+ json_name: "sourceContext",
112
+ proto3_optional: false
113
+ )
114
+ # Included interfaces. See [Mixin][].
115
+ repeated(
116
+ 6,
117
+ "mixins",
118
+ type: :message,
119
+ message_type: "google.protobuf.Mixin"
120
+ )
121
+ # The source syntax of the service.
122
+ optional(
123
+ 7,
124
+ "syntax",
125
+ type: :enum,
126
+ enum_type: "google.protobuf.Syntax",
127
+ proto3_optional: false
128
+ )
129
+ end
130
+
131
+ # Method represents a method of an API interface.
132
+ class Method
133
+ extend Protobug::Message
134
+
135
+ self.full_name = "google.protobuf.Method"
136
+
137
+ # The simple name of this method.
138
+ optional(1, "name", type: :string, proto3_optional: false)
139
+ # A URL of the input message type.
140
+ optional(
141
+ 2,
142
+ "request_type_url",
143
+ type: :string,
144
+ json_name: "requestTypeUrl",
145
+ proto3_optional: false
146
+ )
147
+ # If true, the request is streamed.
148
+ optional(
149
+ 3,
150
+ "request_streaming",
151
+ type: :bool,
152
+ json_name: "requestStreaming",
153
+ proto3_optional: false
154
+ )
155
+ # The URL of the output message type.
156
+ optional(
157
+ 4,
158
+ "response_type_url",
159
+ type: :string,
160
+ json_name: "responseTypeUrl",
161
+ proto3_optional: false
162
+ )
163
+ # If true, the response is streamed.
164
+ optional(
165
+ 5,
166
+ "response_streaming",
167
+ type: :bool,
168
+ json_name: "responseStreaming",
169
+ proto3_optional: false
170
+ )
171
+ # Any metadata attached to the method.
172
+ repeated(
173
+ 6,
174
+ "options",
175
+ type: :message,
176
+ message_type: "google.protobuf.Option"
177
+ )
178
+ # The source syntax of this method.
179
+ optional(
180
+ 7,
181
+ "syntax",
182
+ type: :enum,
183
+ enum_type: "google.protobuf.Syntax",
184
+ proto3_optional: false
185
+ )
186
+ end
187
+
188
+ # Declares an API Interface to be included in this interface. The including
189
+ # interface must redeclare all the methods from the included interface, but
190
+ # documentation and options are inherited as follows:
191
+ #
192
+ # - If after comment and whitespace stripping, the documentation
193
+ # string of the redeclared method is empty, it will be inherited
194
+ # from the original method.
195
+ #
196
+ # - Each annotation belonging to the service config (http,
197
+ # visibility) which is not set in the redeclared method will be
198
+ # inherited.
199
+ #
200
+ # - If an http annotation is inherited, the path pattern will be
201
+ # modified as follows. Any version prefix will be replaced by the
202
+ # version of the including interface plus the [root][] path if
203
+ # specified.
204
+ #
205
+ # Example of a simple mixin:
206
+ #
207
+ # package google.acl.v1;
208
+ # service AccessControl {
209
+ # // Get the underlying ACL object.
210
+ # rpc GetAcl(GetAclRequest) returns (Acl) {
211
+ # option (google.api.http).get = "/v1/{resource=**}:getAcl";
212
+ # }
213
+ # }
214
+ #
215
+ # package google.storage.v2;
216
+ # service Storage {
217
+ # rpc GetAcl(GetAclRequest) returns (Acl);
218
+ #
219
+ # // Get a data record.
220
+ # rpc GetData(GetDataRequest) returns (Data) {
221
+ # option (google.api.http).get = "/v2/{resource=**}";
222
+ # }
223
+ # }
224
+ #
225
+ # Example of a mixin configuration:
226
+ #
227
+ # apis:
228
+ # - name: google.storage.v2.Storage
229
+ # mixins:
230
+ # - name: google.acl.v1.AccessControl
231
+ #
232
+ # The mixin construct implies that all methods in `AccessControl` are
233
+ # also declared with same name and request/response types in
234
+ # `Storage`. A documentation generator or annotation processor will
235
+ # see the effective `Storage.GetAcl` method after inherting
236
+ # documentation and annotations as follows:
237
+ #
238
+ # service Storage {
239
+ # // Get the underlying ACL object.
240
+ # rpc GetAcl(GetAclRequest) returns (Acl) {
241
+ # option (google.api.http).get = "/v2/{resource=**}:getAcl";
242
+ # }
243
+ # ...
244
+ # }
245
+ #
246
+ # Note how the version in the path pattern changed from `v1` to `v2`.
247
+ #
248
+ # If the `root` field in the mixin is specified, it should be a
249
+ # relative path under which inherited HTTP paths are placed. Example:
250
+ #
251
+ # apis:
252
+ # - name: google.storage.v2.Storage
253
+ # mixins:
254
+ # - name: google.acl.v1.AccessControl
255
+ # root: acls
256
+ #
257
+ # This implies the following inherited HTTP annotation:
258
+ #
259
+ # service Storage {
260
+ # // Get the underlying ACL object.
261
+ # rpc GetAcl(GetAclRequest) returns (Acl) {
262
+ # option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
263
+ # }
264
+ # ...
265
+ # }
266
+ class Mixin
267
+ extend Protobug::Message
268
+
269
+ self.full_name = "google.protobuf.Mixin"
270
+
271
+ # The fully qualified name of the interface which is included.
272
+ optional(1, "name", type: :string, proto3_optional: false)
273
+ # If non-empty specifies a path under which inherited HTTP paths
274
+ # are rooted.
275
+ optional(2, "root", type: :string, proto3_optional: false)
276
+ end
277
+
278
+ def self.register_api_protos(registry)
279
+ Google::Protobuf.register_source_context_protos(registry)
280
+ Google::Protobuf.register_type_protos(registry)
281
+ registry.register(Google::Protobuf::Api)
282
+ registry.register(Google::Protobuf::Method)
283
+ registry.register(Google::Protobuf::Mixin)
284
+ end
285
+ end
286
+ end