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