blob: a55c738d10f47cfed48bf1524ad50bb3957e0845 [file] [log] [blame]
khenaidoo5fc5cea2021-08-11 17:39:16 -04001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15// * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// Code generated by protoc-gen-go. DO NOT EDIT.
32// source: google/protobuf/any.proto
33
34// Package anypb contains generated types for google/protobuf/any.proto.
35//
36// The Any message is a dynamic representation of any other message value.
37// It is functionally a tuple of the full name of the remote message type and
38// the serialized bytes of the remote message value.
39//
Joey Armstrongba3d9d12024-01-15 14:22:11 -050040// # Constructing an Any
khenaidoo5fc5cea2021-08-11 17:39:16 -040041//
42// An Any message containing another message value is constructed using New:
43//
44// any, err := anypb.New(m)
45// if err != nil {
46// ... // handle error
47// }
48// ... // make use of any
49//
Joey Armstrongba3d9d12024-01-15 14:22:11 -050050// # Unmarshaling an Any
khenaidoo5fc5cea2021-08-11 17:39:16 -040051//
52// With a populated Any message, the underlying message can be serialized into
53// a remote concrete message value in a few ways.
54//
55// If the exact concrete type is known, then a new (or pre-existing) instance
56// of that message can be passed to the UnmarshalTo method:
57//
58// m := new(foopb.MyMessage)
59// if err := any.UnmarshalTo(m); err != nil {
60// ... // handle error
61// }
62// ... // make use of m
63//
64// If the exact concrete type is not known, then the UnmarshalNew method can be
65// used to unmarshal the contents into a new instance of the remote message type:
66//
67// m, err := any.UnmarshalNew()
68// if err != nil {
69// ... // handle error
70// }
71// ... // make use of m
72//
73// UnmarshalNew uses the global type registry to resolve the message type and
74// construct a new instance of that message to unmarshal into. In order for a
75// message type to appear in the global registry, the Go type representing that
76// protobuf message type must be linked into the Go binary. For messages
77// generated by protoc-gen-go, this is achieved through an import of the
78// generated Go package representing a .proto file.
79//
80// A common pattern with UnmarshalNew is to use a type switch with the resulting
81// proto.Message value:
82//
83// switch m := m.(type) {
84// case *foopb.MyMessage:
85// ... // make use of m as a *foopb.MyMessage
86// case *barpb.OtherMessage:
87// ... // make use of m as a *barpb.OtherMessage
88// case *bazpb.SomeMessage:
89// ... // make use of m as a *bazpb.SomeMessage
90// }
91//
92// This pattern ensures that the generated packages containing the message types
93// listed in the case clauses are linked into the Go binary and therefore also
94// registered in the global registry.
95//
Joey Armstrongba3d9d12024-01-15 14:22:11 -050096// # Type checking an Any
khenaidoo5fc5cea2021-08-11 17:39:16 -040097//
98// In order to type check whether an Any message represents some other message,
99// then use the MessageIs method:
100//
101// if any.MessageIs((*foopb.MyMessage)(nil)) {
102// ... // make use of any, knowing that it contains a foopb.MyMessage
103// }
104//
105// The MessageIs method can also be used with an allocated instance of the target
106// message type if the intention is to unmarshal into it if the type matches:
107//
108// m := new(foopb.MyMessage)
109// if any.MessageIs(m) {
110// if err := any.UnmarshalTo(m); err != nil {
111// ... // handle error
112// }
113// ... // make use of m
114// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400115package anypb
116
117import (
118 proto "google.golang.org/protobuf/proto"
119 protoreflect "google.golang.org/protobuf/reflect/protoreflect"
120 protoregistry "google.golang.org/protobuf/reflect/protoregistry"
121 protoimpl "google.golang.org/protobuf/runtime/protoimpl"
122 reflect "reflect"
123 strings "strings"
124 sync "sync"
125)
126
127// `Any` contains an arbitrary serialized protocol buffer message along with a
128// URL that describes the type of the serialized message.
129//
130// Protobuf library provides support to pack/unpack Any values in the form
131// of utility functions or additional generated methods of the Any type.
132//
133// Example 1: Pack and unpack a message in C++.
134//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500135// Foo foo = ...;
136// Any any;
137// any.PackFrom(foo);
138// ...
139// if (any.UnpackTo(&foo)) {
140// ...
141// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400142//
143// Example 2: Pack and unpack a message in Java.
144//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500145// Foo foo = ...;
146// Any any = Any.pack(foo);
147// ...
148// if (any.is(Foo.class)) {
149// foo = any.unpack(Foo.class);
150// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400151//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500152// Example 3: Pack and unpack a message in Python.
khenaidoo5fc5cea2021-08-11 17:39:16 -0400153//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500154// foo = Foo(...)
155// any = Any()
156// any.Pack(foo)
157// ...
158// if any.Is(Foo.DESCRIPTOR):
159// any.Unpack(foo)
160// ...
khenaidoo5fc5cea2021-08-11 17:39:16 -0400161//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500162// Example 4: Pack and unpack a message in Go
khenaidoo5fc5cea2021-08-11 17:39:16 -0400163//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500164// foo := &pb.Foo{...}
165// any, err := anypb.New(foo)
166// if err != nil {
167// ...
168// }
169// ...
170// foo := &pb.Foo{}
171// if err := any.UnmarshalTo(foo); err != nil {
172// ...
173// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400174//
175// The pack methods provided by protobuf library will by default use
176// 'type.googleapis.com/full.type.name' as the type URL and the unpack
177// methods only use the fully qualified type name after the last '/'
178// in the type URL, for example "foo.bar.com/x/y.z" will yield type
179// name "y.z".
180//
khenaidoo5fc5cea2021-08-11 17:39:16 -0400181// JSON
182// ====
183// The JSON representation of an `Any` value uses the regular
184// representation of the deserialized, embedded message, with an
185// additional field `@type` which contains the type URL. Example:
186//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500187// package google.profile;
188// message Person {
189// string first_name = 1;
190// string last_name = 2;
191// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400192//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500193// {
194// "@type": "type.googleapis.com/google.profile.Person",
195// "firstName": <string>,
196// "lastName": <string>
197// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400198//
199// If the embedded message type is well-known and has a custom JSON
200// representation, that representation will be embedded adding a field
201// `value` which holds the custom JSON in addition to the `@type`
202// field. Example (for message [google.protobuf.Duration][]):
203//
Joey Armstrongba3d9d12024-01-15 14:22:11 -0500204// {
205// "@type": "type.googleapis.com/google.protobuf.Duration",
206// "value": "1.212s"
207// }
khenaidoo5fc5cea2021-08-11 17:39:16 -0400208type Any struct {
209 state protoimpl.MessageState
210 sizeCache protoimpl.SizeCache
211 unknownFields protoimpl.UnknownFields
212
213 // A URL/resource name that uniquely identifies the type of the serialized
214 // protocol buffer message. This string must contain at least
215 // one "/" character. The last segment of the URL's path must represent
216 // the fully qualified name of the type (as in
217 // `path/google.protobuf.Duration`). The name should be in a canonical form
218 // (e.g., leading "." is not accepted).
219 //
220 // In practice, teams usually precompile into the binary all types that they
221 // expect it to use in the context of Any. However, for URLs which use the
222 // scheme `http`, `https`, or no scheme, one can optionally set up a type
223 // server that maps type URLs to message definitions as follows:
224 //
225 // * If no scheme is provided, `https` is assumed.
226 // * An HTTP GET on the URL must yield a [google.protobuf.Type][]
227 // value in binary format, or produce an error.
228 // * Applications are allowed to cache lookup results based on the
229 // URL, or have them precompiled into a binary to avoid any
230 // lookup. Therefore, binary compatibility needs to be preserved
231 // on changes to types. (Use versioned type names to manage
232 // breaking changes.)
233 //
234 // Note: this functionality is not currently available in the official
235 // protobuf release, and it is not used for type URLs beginning with
236 // type.googleapis.com.
237 //
238 // Schemes other than `http`, `https` (or the empty scheme) might be
239 // used with implementation specific semantics.
240 //
241 TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
242 // Must be a valid serialized protocol buffer of the above specified type.
243 Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
244}
245
246// New marshals src into a new Any instance.
247func New(src proto.Message) (*Any, error) {
248 dst := new(Any)
249 if err := dst.MarshalFrom(src); err != nil {
250 return nil, err
251 }
252 return dst, nil
253}
254
255// MarshalFrom marshals src into dst as the underlying message
256// using the provided marshal options.
257//
258// If no options are specified, call dst.MarshalFrom instead.
259func MarshalFrom(dst *Any, src proto.Message, opts proto.MarshalOptions) error {
260 const urlPrefix = "type.googleapis.com/"
261 if src == nil {
262 return protoimpl.X.NewError("invalid nil source message")
263 }
264 b, err := opts.Marshal(src)
265 if err != nil {
266 return err
267 }
268 dst.TypeUrl = urlPrefix + string(src.ProtoReflect().Descriptor().FullName())
269 dst.Value = b
270 return nil
271}
272
273// UnmarshalTo unmarshals the underlying message from src into dst
274// using the provided unmarshal options.
275// It reports an error if dst is not of the right message type.
276//
277// If no options are specified, call src.UnmarshalTo instead.
278func UnmarshalTo(src *Any, dst proto.Message, opts proto.UnmarshalOptions) error {
279 if src == nil {
280 return protoimpl.X.NewError("invalid nil source message")
281 }
282 if !src.MessageIs(dst) {
283 got := dst.ProtoReflect().Descriptor().FullName()
284 want := src.MessageName()
285 return protoimpl.X.NewError("mismatched message type: got %q, want %q", got, want)
286 }
287 return opts.Unmarshal(src.GetValue(), dst)
288}
289
290// UnmarshalNew unmarshals the underlying message from src into dst,
291// which is newly created message using a type resolved from the type URL.
292// The message type is resolved according to opt.Resolver,
293// which should implement protoregistry.MessageTypeResolver.
294// It reports an error if the underlying message type could not be resolved.
295//
296// If no options are specified, call src.UnmarshalNew instead.
297func UnmarshalNew(src *Any, opts proto.UnmarshalOptions) (dst proto.Message, err error) {
298 if src.GetTypeUrl() == "" {
299 return nil, protoimpl.X.NewError("invalid empty type URL")
300 }
301 if opts.Resolver == nil {
302 opts.Resolver = protoregistry.GlobalTypes
303 }
304 r, ok := opts.Resolver.(protoregistry.MessageTypeResolver)
305 if !ok {
306 return nil, protoregistry.NotFound
307 }
308 mt, err := r.FindMessageByURL(src.GetTypeUrl())
309 if err != nil {
310 if err == protoregistry.NotFound {
311 return nil, err
312 }
313 return nil, protoimpl.X.NewError("could not resolve %q: %v", src.GetTypeUrl(), err)
314 }
315 dst = mt.New().Interface()
316 return dst, opts.Unmarshal(src.GetValue(), dst)
317}
318
319// MessageIs reports whether the underlying message is of the same type as m.
320func (x *Any) MessageIs(m proto.Message) bool {
321 if m == nil {
322 return false
323 }
324 url := x.GetTypeUrl()
325 name := string(m.ProtoReflect().Descriptor().FullName())
326 if !strings.HasSuffix(url, name) {
327 return false
328 }
329 return len(url) == len(name) || url[len(url)-len(name)-1] == '/'
330}
331
332// MessageName reports the full name of the underlying message,
333// returning an empty string if invalid.
334func (x *Any) MessageName() protoreflect.FullName {
335 url := x.GetTypeUrl()
336 name := protoreflect.FullName(url)
337 if i := strings.LastIndexByte(url, '/'); i >= 0 {
338 name = name[i+len("/"):]
339 }
340 if !name.IsValid() {
341 return ""
342 }
343 return name
344}
345
346// MarshalFrom marshals m into x as the underlying message.
347func (x *Any) MarshalFrom(m proto.Message) error {
348 return MarshalFrom(x, m, proto.MarshalOptions{})
349}
350
351// UnmarshalTo unmarshals the contents of the underlying message of x into m.
352// It resets m before performing the unmarshal operation.
353// It reports an error if m is not of the right message type.
354func (x *Any) UnmarshalTo(m proto.Message) error {
355 return UnmarshalTo(x, m, proto.UnmarshalOptions{})
356}
357
358// UnmarshalNew unmarshals the contents of the underlying message of x into
359// a newly allocated message of the specified type.
360// It reports an error if the underlying message type could not be resolved.
361func (x *Any) UnmarshalNew() (proto.Message, error) {
362 return UnmarshalNew(x, proto.UnmarshalOptions{})
363}
364
365func (x *Any) Reset() {
366 *x = Any{}
367 if protoimpl.UnsafeEnabled {
368 mi := &file_google_protobuf_any_proto_msgTypes[0]
369 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
370 ms.StoreMessageInfo(mi)
371 }
372}
373
374func (x *Any) String() string {
375 return protoimpl.X.MessageStringOf(x)
376}
377
378func (*Any) ProtoMessage() {}
379
380func (x *Any) ProtoReflect() protoreflect.Message {
381 mi := &file_google_protobuf_any_proto_msgTypes[0]
382 if protoimpl.UnsafeEnabled && x != nil {
383 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
384 if ms.LoadMessageInfo() == nil {
385 ms.StoreMessageInfo(mi)
386 }
387 return ms
388 }
389 return mi.MessageOf(x)
390}
391
392// Deprecated: Use Any.ProtoReflect.Descriptor instead.
393func (*Any) Descriptor() ([]byte, []int) {
394 return file_google_protobuf_any_proto_rawDescGZIP(), []int{0}
395}
396
397func (x *Any) GetTypeUrl() string {
398 if x != nil {
399 return x.TypeUrl
400 }
401 return ""
402}
403
404func (x *Any) GetValue() []byte {
405 if x != nil {
406 return x.Value
407 }
408 return nil
409}
410
411var File_google_protobuf_any_proto protoreflect.FileDescriptor
412
413var file_google_protobuf_any_proto_rawDesc = []byte{
414 0x0a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
415 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x6f,
416 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x36, 0x0a, 0x03,
417 0x41, 0x6e, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18,
418 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x79, 0x70, 0x65, 0x55, 0x72, 0x6c, 0x12, 0x14,
419 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76,
420 0x61, 0x6c, 0x75, 0x65, 0x42, 0x76, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
421 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x08, 0x41, 0x6e, 0x79,
422 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
423 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
424 0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x2f,
425 0x61, 0x6e, 0x79, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x47, 0x50, 0x42, 0xaa, 0x02, 0x1e, 0x47, 0x6f,
426 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x57, 0x65,
427 0x6c, 0x6c, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72,
428 0x6f, 0x74, 0x6f, 0x33,
429}
430
431var (
432 file_google_protobuf_any_proto_rawDescOnce sync.Once
433 file_google_protobuf_any_proto_rawDescData = file_google_protobuf_any_proto_rawDesc
434)
435
436func file_google_protobuf_any_proto_rawDescGZIP() []byte {
437 file_google_protobuf_any_proto_rawDescOnce.Do(func() {
438 file_google_protobuf_any_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_protobuf_any_proto_rawDescData)
439 })
440 return file_google_protobuf_any_proto_rawDescData
441}
442
443var file_google_protobuf_any_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
444var file_google_protobuf_any_proto_goTypes = []interface{}{
445 (*Any)(nil), // 0: google.protobuf.Any
446}
447var file_google_protobuf_any_proto_depIdxs = []int32{
448 0, // [0:0] is the sub-list for method output_type
449 0, // [0:0] is the sub-list for method input_type
450 0, // [0:0] is the sub-list for extension type_name
451 0, // [0:0] is the sub-list for extension extendee
452 0, // [0:0] is the sub-list for field type_name
453}
454
455func init() { file_google_protobuf_any_proto_init() }
456func file_google_protobuf_any_proto_init() {
457 if File_google_protobuf_any_proto != nil {
458 return
459 }
460 if !protoimpl.UnsafeEnabled {
461 file_google_protobuf_any_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
462 switch v := v.(*Any); i {
463 case 0:
464 return &v.state
465 case 1:
466 return &v.sizeCache
467 case 2:
468 return &v.unknownFields
469 default:
470 return nil
471 }
472 }
473 }
474 type x struct{}
475 out := protoimpl.TypeBuilder{
476 File: protoimpl.DescBuilder{
477 GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
478 RawDescriptor: file_google_protobuf_any_proto_rawDesc,
479 NumEnums: 0,
480 NumMessages: 1,
481 NumExtensions: 0,
482 NumServices: 0,
483 },
484 GoTypes: file_google_protobuf_any_proto_goTypes,
485 DependencyIndexes: file_google_protobuf_any_proto_depIdxs,
486 MessageInfos: file_google_protobuf_any_proto_msgTypes,
487 }.Build()
488 File_google_protobuf_any_proto = out.File
489 file_google_protobuf_any_proto_rawDesc = nil
490 file_google_protobuf_any_proto_goTypes = nil
491 file_google_protobuf_any_proto_depIdxs = nil
492}