xref: /aosp_15_r20/external/golang-protobuf/types/known/anypb/any.pb.go (revision 1c12ee1efe575feb122dbf939ff15148a3b3e8f2)
1// 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// # Constructing an Any
41//
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//
50// # Unmarshaling an Any
51//
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//
96// # Type checking an Any
97//
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//	}
115package 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//
135//	Foo foo = ...;
136//	Any any;
137//	any.PackFrom(foo);
138//	...
139//	if (any.UnpackTo(&foo)) {
140//	  ...
141//	}
142//
143// Example 2: Pack and unpack a message in Java.
144//
145//	Foo foo = ...;
146//	Any any = Any.pack(foo);
147//	...
148//	if (any.is(Foo.class)) {
149//	  foo = any.unpack(Foo.class);
150//	}
151//	// or ...
152//	if (any.isSameTypeAs(Foo.getDefaultInstance())) {
153//	  foo = any.unpack(Foo.getDefaultInstance());
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// # JSON
186//
187// The JSON representation of an `Any` value uses the regular
188// representation of the deserialized, embedded message, with an
189// additional field `@type` which contains the type URL. Example:
190//
191//	package google.profile;
192//	message Person {
193//	  string first_name = 1;
194//	  string last_name = 2;
195//	}
196//
197//	{
198//	  "@type": "type.googleapis.com/google.profile.Person",
199//	  "firstName": <string>,
200//	  "lastName": <string>
201//	}
202//
203// If the embedded message type is well-known and has a custom JSON
204// representation, that representation will be embedded adding a field
205// `value` which holds the custom JSON in addition to the `@type`
206// field. Example (for message [google.protobuf.Duration][]):
207//
208//	{
209//	  "@type": "type.googleapis.com/google.protobuf.Duration",
210//	  "value": "1.212s"
211//	}
212type Any struct {
213	state         protoimpl.MessageState
214	sizeCache     protoimpl.SizeCache
215	unknownFields protoimpl.UnknownFields
216
217	// A URL/resource name that uniquely identifies the type of the serialized
218	// protocol buffer message. This string must contain at least
219	// one "/" character. The last segment of the URL's path must represent
220	// the fully qualified name of the type (as in
221	// `path/google.protobuf.Duration`). The name should be in a canonical form
222	// (e.g., leading "." is not accepted).
223	//
224	// In practice, teams usually precompile into the binary all types that they
225	// expect it to use in the context of Any. However, for URLs which use the
226	// scheme `http`, `https`, or no scheme, one can optionally set up a type
227	// server that maps type URLs to message definitions as follows:
228	//
229	//   - If no scheme is provided, `https` is assumed.
230	//   - An HTTP GET on the URL must yield a [google.protobuf.Type][]
231	//     value in binary format, or produce an error.
232	//   - Applications are allowed to cache lookup results based on the
233	//     URL, or have them precompiled into a binary to avoid any
234	//     lookup. Therefore, binary compatibility needs to be preserved
235	//     on changes to types. (Use versioned type names to manage
236	//     breaking changes.)
237	//
238	// Note: this functionality is not currently available in the official
239	// protobuf release, and it is not used for type URLs beginning with
240	// type.googleapis.com.
241	//
242	// Schemes other than `http`, `https` (or the empty scheme) might be
243	// used with implementation specific semantics.
244	TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
245	// Must be a valid serialized protocol buffer of the above specified type.
246	Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
247}
248
249// New marshals src into a new Any instance.
250func New(src proto.Message) (*Any, error) {
251	dst := new(Any)
252	if err := dst.MarshalFrom(src); err != nil {
253		return nil, err
254	}
255	return dst, nil
256}
257
258// MarshalFrom marshals src into dst as the underlying message
259// using the provided marshal options.
260//
261// If no options are specified, call dst.MarshalFrom instead.
262func MarshalFrom(dst *Any, src proto.Message, opts proto.MarshalOptions) error {
263	const urlPrefix = "type.googleapis.com/"
264	if src == nil {
265		return protoimpl.X.NewError("invalid nil source message")
266	}
267	b, err := opts.Marshal(src)
268	if err != nil {
269		return err
270	}
271	dst.TypeUrl = urlPrefix + string(src.ProtoReflect().Descriptor().FullName())
272	dst.Value = b
273	return nil
274}
275
276// UnmarshalTo unmarshals the underlying message from src into dst
277// using the provided unmarshal options.
278// It reports an error if dst is not of the right message type.
279//
280// If no options are specified, call src.UnmarshalTo instead.
281func UnmarshalTo(src *Any, dst proto.Message, opts proto.UnmarshalOptions) error {
282	if src == nil {
283		return protoimpl.X.NewError("invalid nil source message")
284	}
285	if !src.MessageIs(dst) {
286		got := dst.ProtoReflect().Descriptor().FullName()
287		want := src.MessageName()
288		return protoimpl.X.NewError("mismatched message type: got %q, want %q", got, want)
289	}
290	return opts.Unmarshal(src.GetValue(), dst)
291}
292
293// UnmarshalNew unmarshals the underlying message from src into dst,
294// which is newly created message using a type resolved from the type URL.
295// The message type is resolved according to opt.Resolver,
296// which should implement protoregistry.MessageTypeResolver.
297// It reports an error if the underlying message type could not be resolved.
298//
299// If no options are specified, call src.UnmarshalNew instead.
300func UnmarshalNew(src *Any, opts proto.UnmarshalOptions) (dst proto.Message, err error) {
301	if src.GetTypeUrl() == "" {
302		return nil, protoimpl.X.NewError("invalid empty type URL")
303	}
304	if opts.Resolver == nil {
305		opts.Resolver = protoregistry.GlobalTypes
306	}
307	r, ok := opts.Resolver.(protoregistry.MessageTypeResolver)
308	if !ok {
309		return nil, protoregistry.NotFound
310	}
311	mt, err := r.FindMessageByURL(src.GetTypeUrl())
312	if err != nil {
313		if err == protoregistry.NotFound {
314			return nil, err
315		}
316		return nil, protoimpl.X.NewError("could not resolve %q: %v", src.GetTypeUrl(), err)
317	}
318	dst = mt.New().Interface()
319	return dst, opts.Unmarshal(src.GetValue(), dst)
320}
321
322// MessageIs reports whether the underlying message is of the same type as m.
323func (x *Any) MessageIs(m proto.Message) bool {
324	if m == nil {
325		return false
326	}
327	url := x.GetTypeUrl()
328	name := string(m.ProtoReflect().Descriptor().FullName())
329	if !strings.HasSuffix(url, name) {
330		return false
331	}
332	return len(url) == len(name) || url[len(url)-len(name)-1] == '/'
333}
334
335// MessageName reports the full name of the underlying message,
336// returning an empty string if invalid.
337func (x *Any) MessageName() protoreflect.FullName {
338	url := x.GetTypeUrl()
339	name := protoreflect.FullName(url)
340	if i := strings.LastIndexByte(url, '/'); i >= 0 {
341		name = name[i+len("/"):]
342	}
343	if !name.IsValid() {
344		return ""
345	}
346	return name
347}
348
349// MarshalFrom marshals m into x as the underlying message.
350func (x *Any) MarshalFrom(m proto.Message) error {
351	return MarshalFrom(x, m, proto.MarshalOptions{})
352}
353
354// UnmarshalTo unmarshals the contents of the underlying message of x into m.
355// It resets m before performing the unmarshal operation.
356// It reports an error if m is not of the right message type.
357func (x *Any) UnmarshalTo(m proto.Message) error {
358	return UnmarshalTo(x, m, proto.UnmarshalOptions{})
359}
360
361// UnmarshalNew unmarshals the contents of the underlying message of x into
362// a newly allocated message of the specified type.
363// It reports an error if the underlying message type could not be resolved.
364func (x *Any) UnmarshalNew() (proto.Message, error) {
365	return UnmarshalNew(x, proto.UnmarshalOptions{})
366}
367
368func (x *Any) Reset() {
369	*x = Any{}
370	if protoimpl.UnsafeEnabled {
371		mi := &file_google_protobuf_any_proto_msgTypes[0]
372		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
373		ms.StoreMessageInfo(mi)
374	}
375}
376
377func (x *Any) String() string {
378	return protoimpl.X.MessageStringOf(x)
379}
380
381func (*Any) ProtoMessage() {}
382
383func (x *Any) ProtoReflect() protoreflect.Message {
384	mi := &file_google_protobuf_any_proto_msgTypes[0]
385	if protoimpl.UnsafeEnabled && x != nil {
386		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
387		if ms.LoadMessageInfo() == nil {
388			ms.StoreMessageInfo(mi)
389		}
390		return ms
391	}
392	return mi.MessageOf(x)
393}
394
395// Deprecated: Use Any.ProtoReflect.Descriptor instead.
396func (*Any) Descriptor() ([]byte, []int) {
397	return file_google_protobuf_any_proto_rawDescGZIP(), []int{0}
398}
399
400func (x *Any) GetTypeUrl() string {
401	if x != nil {
402		return x.TypeUrl
403	}
404	return ""
405}
406
407func (x *Any) GetValue() []byte {
408	if x != nil {
409		return x.Value
410	}
411	return nil
412}
413
414var File_google_protobuf_any_proto protoreflect.FileDescriptor
415
416var file_google_protobuf_any_proto_rawDesc = []byte{
417	0x0a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
418	0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x67, 0x6f, 0x6f,
419	0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x36, 0x0a, 0x03,
420	0x41, 0x6e, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18,
421	0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x79, 0x70, 0x65, 0x55, 0x72, 0x6c, 0x12, 0x14,
422	0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76,
423	0x61, 0x6c, 0x75, 0x65, 0x42, 0x76, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
424	0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x08, 0x41, 0x6e, 0x79,
425	0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
426	0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
427	0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x2f,
428	0x61, 0x6e, 0x79, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x47, 0x50, 0x42, 0xaa, 0x02, 0x1e, 0x47, 0x6f,
429	0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x57, 0x65,
430	0x6c, 0x6c, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72,
431	0x6f, 0x74, 0x6f, 0x33,
432}
433
434var (
435	file_google_protobuf_any_proto_rawDescOnce sync.Once
436	file_google_protobuf_any_proto_rawDescData = file_google_protobuf_any_proto_rawDesc
437)
438
439func file_google_protobuf_any_proto_rawDescGZIP() []byte {
440	file_google_protobuf_any_proto_rawDescOnce.Do(func() {
441		file_google_protobuf_any_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_protobuf_any_proto_rawDescData)
442	})
443	return file_google_protobuf_any_proto_rawDescData
444}
445
446var file_google_protobuf_any_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
447var file_google_protobuf_any_proto_goTypes = []interface{}{
448	(*Any)(nil), // 0: google.protobuf.Any
449}
450var file_google_protobuf_any_proto_depIdxs = []int32{
451	0, // [0:0] is the sub-list for method output_type
452	0, // [0:0] is the sub-list for method input_type
453	0, // [0:0] is the sub-list for extension type_name
454	0, // [0:0] is the sub-list for extension extendee
455	0, // [0:0] is the sub-list for field type_name
456}
457
458func init() { file_google_protobuf_any_proto_init() }
459func file_google_protobuf_any_proto_init() {
460	if File_google_protobuf_any_proto != nil {
461		return
462	}
463	if !protoimpl.UnsafeEnabled {
464		file_google_protobuf_any_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
465			switch v := v.(*Any); i {
466			case 0:
467				return &v.state
468			case 1:
469				return &v.sizeCache
470			case 2:
471				return &v.unknownFields
472			default:
473				return nil
474			}
475		}
476	}
477	type x struct{}
478	out := protoimpl.TypeBuilder{
479		File: protoimpl.DescBuilder{
480			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
481			RawDescriptor: file_google_protobuf_any_proto_rawDesc,
482			NumEnums:      0,
483			NumMessages:   1,
484			NumExtensions: 0,
485			NumServices:   0,
486		},
487		GoTypes:           file_google_protobuf_any_proto_goTypes,
488		DependencyIndexes: file_google_protobuf_any_proto_depIdxs,
489		MessageInfos:      file_google_protobuf_any_proto_msgTypes,
490	}.Build()
491	File_google_protobuf_any_proto = out.File
492	file_google_protobuf_any_proto_rawDesc = nil
493	file_google_protobuf_any_proto_goTypes = nil
494	file_google_protobuf_any_proto_depIdxs = nil
495}
496