buffa_types/generated/google.protobuf.any.rs
1// @generated by protoc-gen-buffa. DO NOT EDIT.
2// source: google/protobuf/any.proto
3
4/// `Any` contains an arbitrary serialized protocol buffer message along with a
5/// URL that describes the type of the serialized message.
6///
7/// Protobuf library provides support to pack/unpack Any values in the form
8/// of utility functions or additional generated methods of the Any type.
9///
10/// Example 1: Pack and unpack a message in C++.
11///
12/// ```text
13/// Foo foo = ...;
14/// Any any;
15/// any.PackFrom(foo);
16/// ...
17/// if (any.UnpackTo(&foo)) {
18/// ...
19/// }
20/// ```
21///
22/// Example 2: Pack and unpack a message in Java.
23///
24/// ```text
25/// Foo foo = ...;
26/// Any any = Any.pack(foo);
27/// ...
28/// if (any.is(Foo.class)) {
29/// foo = any.unpack(Foo.class);
30/// }
31/// // or ...
32/// if (any.isSameTypeAs(Foo.getDefaultInstance())) {
33/// foo = any.unpack(Foo.getDefaultInstance());
34/// }
35/// ```
36///
37/// Example 3: Pack and unpack a message in Python.
38///
39/// ```text
40/// foo = Foo(...)
41/// any = Any()
42/// any.Pack(foo)
43/// ...
44/// if any.Is(Foo.DESCRIPTOR):
45/// any.Unpack(foo)
46/// ...
47/// ```
48///
49/// Example 4: Pack and unpack a message in Go
50///
51/// ```text
52/// foo := &pb.Foo{...}
53/// any, err := anypb.New(foo)
54/// if err != nil {
55/// ...
56/// }
57/// ...
58/// foo := &pb.Foo{}
59/// if err := any.UnmarshalTo(foo); err != nil {
60/// ...
61/// }
62/// ```
63///
64/// The pack methods provided by protobuf library will by default use
65/// 'type.googleapis.com/full.type.name' as the type URL and the unpack
66/// methods only use the fully qualified type name after the last '/'
67/// in the type URL, for example "foo.bar.com/x/y.z" will yield type
68/// name "y.z".
69///
70/// JSON
71/// ====
72/// The JSON representation of an `Any` value uses the regular
73/// representation of the deserialized, embedded message, with an
74/// additional field `@type` which contains the type URL. Example:
75///
76/// ```text
77/// package google.profile;
78/// message Person {
79/// string first_name = 1;
80/// string last_name = 2;
81/// }
82///
83/// {
84/// "@type": "type.googleapis.com/google.profile.Person",
85/// "firstName": <string>,
86/// "lastName": <string>
87/// }
88/// ```
89///
90/// If the embedded message type is well-known and has a custom JSON
91/// representation, that representation will be embedded adding a field
92/// `value` which holds the custom JSON in addition to the `@type`
93/// field. Example (for message \[google.protobuf.Duration\]\[\]):
94///
95/// ```text
96/// {
97/// "@type": "type.googleapis.com/google.protobuf.Duration",
98/// "value": "1.212s"
99/// }
100/// ```
101#[derive(Clone, PartialEq, Default)]
102#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
103pub struct Any {
104 /// A URL/resource name that uniquely identifies the type of the serialized
105 /// protocol buffer message. This string must contain at least
106 /// one "/" character. The last segment of the URL's path must represent
107 /// the fully qualified name of the type (as in
108 /// `path/google.protobuf.Duration`). The name should be in a canonical form
109 /// (e.g., leading "." is not accepted).
110 ///
111 /// In practice, teams usually precompile into the binary all types that they
112 /// expect it to use in the context of Any. However, for URLs which use the
113 /// scheme `http`, `https`, or no scheme, one can optionally set up a type
114 /// server that maps type URLs to message definitions as follows:
115 ///
116 /// * If no scheme is provided, `https` is assumed.
117 /// * An HTTP GET on the URL must yield a \[google.protobuf.Type\]\[\]
118 /// value in binary format, or produce an error.
119 /// * Applications are allowed to cache lookup results based on the
120 /// URL, or have them precompiled into a binary to avoid any
121 /// lookup. Therefore, binary compatibility needs to be preserved
122 /// on changes to types. (Use versioned type names to manage
123 /// breaking changes.)
124 ///
125 /// Note: this functionality is not currently available in the official
126 /// protobuf release, and it is not used for type URLs beginning with
127 /// type.googleapis.com. As of May 2023, there are no widely used type server
128 /// implementations and no plans to implement one.
129 ///
130 /// Schemes other than `http`, `https` (or the empty scheme) might be
131 /// used with implementation specific semantics.
132 ///
133 /// Field 1: `type_url`
134 pub type_url: ::buffa::alloc::string::String,
135 /// Must be a valid serialized protocol buffer of the above specified type.
136 ///
137 /// Field 2: `value`
138 pub value: ::buffa::alloc::vec::Vec<u8>,
139 #[doc(hidden)]
140 pub __buffa_unknown_fields: ::buffa::UnknownFields,
141 #[doc(hidden)]
142 pub __buffa_cached_size: ::buffa::__private::CachedSize,
143}
144impl ::core::fmt::Debug for Any {
145 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
146 f.debug_struct("Any")
147 .field("type_url", &self.type_url)
148 .field("value", &self.value)
149 .finish()
150 }
151}
152impl Any {
153 /// Protobuf type URL for this message, for use with `Any::pack` and
154 /// `Any::unpack_if`.
155 ///
156 /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
157 pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Any";
158}
159unsafe impl ::buffa::DefaultInstance for Any {
160 fn default_instance() -> &'static Self {
161 static VALUE: ::buffa::__private::OnceBox<Any> = ::buffa::__private::OnceBox::new();
162 VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
163 }
164}
165impl ::buffa::Message for Any {
166 /// Returns the total encoded size in bytes.
167 ///
168 /// The result is a `u32`; the protobuf specification requires all
169 /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
170 /// compliant message will never overflow this type.
171 fn compute_size(&self) -> u32 {
172 #[allow(unused_imports)]
173 use ::buffa::Enumeration as _;
174 let mut size = 0u32;
175 if !self.type_url.is_empty() {
176 size += 1u32 + ::buffa::types::string_encoded_len(&self.type_url) as u32;
177 }
178 if !self.value.is_empty() {
179 size += 1u32 + ::buffa::types::bytes_encoded_len(&self.value) as u32;
180 }
181 size += self.__buffa_unknown_fields.encoded_len() as u32;
182 self.__buffa_cached_size.set(size);
183 size
184 }
185 fn write_to(&self, buf: &mut impl ::buffa::bytes::BufMut) {
186 #[allow(unused_imports)]
187 use ::buffa::Enumeration as _;
188 if !self.type_url.is_empty() {
189 ::buffa::encoding::Tag::new(
190 1u32,
191 ::buffa::encoding::WireType::LengthDelimited,
192 )
193 .encode(buf);
194 ::buffa::types::encode_string(&self.type_url, buf);
195 }
196 if !self.value.is_empty() {
197 ::buffa::encoding::Tag::new(
198 2u32,
199 ::buffa::encoding::WireType::LengthDelimited,
200 )
201 .encode(buf);
202 ::buffa::types::encode_bytes(&self.value, buf);
203 }
204 self.__buffa_unknown_fields.write_to(buf);
205 }
206 fn merge_field(
207 &mut self,
208 tag: ::buffa::encoding::Tag,
209 buf: &mut impl ::buffa::bytes::Buf,
210 depth: u32,
211 ) -> ::core::result::Result<(), ::buffa::DecodeError> {
212 #[allow(unused_imports)]
213 use ::buffa::bytes::Buf as _;
214 #[allow(unused_imports)]
215 use ::buffa::Enumeration as _;
216 match tag.field_number() {
217 1u32 => {
218 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
219 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
220 field_number: 1u32,
221 expected: 2u8,
222 actual: tag.wire_type() as u8,
223 });
224 }
225 ::buffa::types::merge_string(&mut self.type_url, buf)?;
226 }
227 2u32 => {
228 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
229 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
230 field_number: 2u32,
231 expected: 2u8,
232 actual: tag.wire_type() as u8,
233 });
234 }
235 ::buffa::types::merge_bytes(&mut self.value, buf)?;
236 }
237 _ => {
238 self.__buffa_unknown_fields
239 .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
240 }
241 }
242 ::core::result::Result::Ok(())
243 }
244 fn cached_size(&self) -> u32 {
245 self.__buffa_cached_size.get()
246 }
247 fn clear(&mut self) {
248 self.type_url.clear();
249 self.value.clear();
250 self.__buffa_unknown_fields.clear();
251 self.__buffa_cached_size.set(0);
252 }
253}
254impl ::buffa::ExtensionSet for Any {
255 const PROTO_FQN: &'static str = "google.protobuf.Any";
256 fn unknown_fields(&self) -> &::buffa::UnknownFields {
257 &self.__buffa_unknown_fields
258 }
259 fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
260 &mut self.__buffa_unknown_fields
261 }
262}
263#[doc(hidden)]
264pub const __ANY_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
265 type_url: "type.googleapis.com/google.protobuf.Any",
266 text_encode: ::buffa::type_registry::any_encode_text::<Any>,
267 text_merge: ::buffa::type_registry::any_merge_text::<Any>,
268};
269/// `Any` contains an arbitrary serialized protocol buffer message along with a
270/// URL that describes the type of the serialized message.
271///
272/// Protobuf library provides support to pack/unpack Any values in the form
273/// of utility functions or additional generated methods of the Any type.
274///
275/// Example 1: Pack and unpack a message in C++.
276///
277/// ```text
278/// Foo foo = ...;
279/// Any any;
280/// any.PackFrom(foo);
281/// ...
282/// if (any.UnpackTo(&foo)) {
283/// ...
284/// }
285/// ```
286///
287/// Example 2: Pack and unpack a message in Java.
288///
289/// ```text
290/// Foo foo = ...;
291/// Any any = Any.pack(foo);
292/// ...
293/// if (any.is(Foo.class)) {
294/// foo = any.unpack(Foo.class);
295/// }
296/// // or ...
297/// if (any.isSameTypeAs(Foo.getDefaultInstance())) {
298/// foo = any.unpack(Foo.getDefaultInstance());
299/// }
300/// ```
301///
302/// Example 3: Pack and unpack a message in Python.
303///
304/// ```text
305/// foo = Foo(...)
306/// any = Any()
307/// any.Pack(foo)
308/// ...
309/// if any.Is(Foo.DESCRIPTOR):
310/// any.Unpack(foo)
311/// ...
312/// ```
313///
314/// Example 4: Pack and unpack a message in Go
315///
316/// ```text
317/// foo := &pb.Foo{...}
318/// any, err := anypb.New(foo)
319/// if err != nil {
320/// ...
321/// }
322/// ...
323/// foo := &pb.Foo{}
324/// if err := any.UnmarshalTo(foo); err != nil {
325/// ...
326/// }
327/// ```
328///
329/// The pack methods provided by protobuf library will by default use
330/// 'type.googleapis.com/full.type.name' as the type URL and the unpack
331/// methods only use the fully qualified type name after the last '/'
332/// in the type URL, for example "foo.bar.com/x/y.z" will yield type
333/// name "y.z".
334///
335/// JSON
336/// ====
337/// The JSON representation of an `Any` value uses the regular
338/// representation of the deserialized, embedded message, with an
339/// additional field `@type` which contains the type URL. Example:
340///
341/// ```text
342/// package google.profile;
343/// message Person {
344/// string first_name = 1;
345/// string last_name = 2;
346/// }
347///
348/// {
349/// "@type": "type.googleapis.com/google.profile.Person",
350/// "firstName": <string>,
351/// "lastName": <string>
352/// }
353/// ```
354///
355/// If the embedded message type is well-known and has a custom JSON
356/// representation, that representation will be embedded adding a field
357/// `value` which holds the custom JSON in addition to the `@type`
358/// field. Example (for message \[google.protobuf.Duration\]\[\]):
359///
360/// ```text
361/// {
362/// "@type": "type.googleapis.com/google.protobuf.Duration",
363/// "value": "1.212s"
364/// }
365/// ```
366#[derive(Clone, Debug, Default)]
367pub struct AnyView<'a> {
368 /// A URL/resource name that uniquely identifies the type of the serialized
369 /// protocol buffer message. This string must contain at least
370 /// one "/" character. The last segment of the URL's path must represent
371 /// the fully qualified name of the type (as in
372 /// `path/google.protobuf.Duration`). The name should be in a canonical form
373 /// (e.g., leading "." is not accepted).
374 ///
375 /// In practice, teams usually precompile into the binary all types that they
376 /// expect it to use in the context of Any. However, for URLs which use the
377 /// scheme `http`, `https`, or no scheme, one can optionally set up a type
378 /// server that maps type URLs to message definitions as follows:
379 ///
380 /// * If no scheme is provided, `https` is assumed.
381 /// * An HTTP GET on the URL must yield a \[google.protobuf.Type\]\[\]
382 /// value in binary format, or produce an error.
383 /// * Applications are allowed to cache lookup results based on the
384 /// URL, or have them precompiled into a binary to avoid any
385 /// lookup. Therefore, binary compatibility needs to be preserved
386 /// on changes to types. (Use versioned type names to manage
387 /// breaking changes.)
388 ///
389 /// Note: this functionality is not currently available in the official
390 /// protobuf release, and it is not used for type URLs beginning with
391 /// type.googleapis.com. As of May 2023, there are no widely used type server
392 /// implementations and no plans to implement one.
393 ///
394 /// Schemes other than `http`, `https` (or the empty scheme) might be
395 /// used with implementation specific semantics.
396 ///
397 /// Field 1: `type_url`
398 pub type_url: &'a str,
399 /// Must be a valid serialized protocol buffer of the above specified type.
400 ///
401 /// Field 2: `value`
402 pub value: &'a [u8],
403 pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
404}
405impl<'a> AnyView<'a> {
406 /// Decode from `buf`, enforcing a recursion depth limit for nested messages.
407 ///
408 /// Called by [`::buffa::MessageView::decode_view`] with [`::buffa::RECURSION_LIMIT`]
409 /// and by generated sub-message decode arms with `depth - 1`.
410 ///
411 /// **Not part of the public API.** Named with a leading underscore to
412 /// signal that it is for generated-code use only.
413 #[doc(hidden)]
414 pub fn _decode_depth(
415 buf: &'a [u8],
416 depth: u32,
417 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
418 let mut view = Self::default();
419 view._merge_into_view(buf, depth)?;
420 ::core::result::Result::Ok(view)
421 }
422 /// Merge fields from `buf` into this view (proto merge semantics).
423 ///
424 /// Repeated fields append; singular fields last-wins; singular
425 /// MESSAGE fields merge recursively. Used by sub-message decode
426 /// arms when the same field appears multiple times on the wire.
427 ///
428 /// **Not part of the public API.**
429 #[doc(hidden)]
430 pub fn _merge_into_view(
431 &mut self,
432 buf: &'a [u8],
433 depth: u32,
434 ) -> ::core::result::Result<(), ::buffa::DecodeError> {
435 let _ = depth;
436 #[allow(unused_variables)]
437 let view = self;
438 let mut cur: &'a [u8] = buf;
439 while !cur.is_empty() {
440 let before_tag = cur;
441 let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
442 match tag.field_number() {
443 1u32 => {
444 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
445 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
446 field_number: 1u32,
447 expected: 2u8,
448 actual: tag.wire_type() as u8,
449 });
450 }
451 view.type_url = ::buffa::types::borrow_str(&mut cur)?;
452 }
453 2u32 => {
454 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
455 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
456 field_number: 2u32,
457 expected: 2u8,
458 actual: tag.wire_type() as u8,
459 });
460 }
461 view.value = ::buffa::types::borrow_bytes(&mut cur)?;
462 }
463 _ => {
464 ::buffa::encoding::skip_field_depth(tag, &mut cur, depth)?;
465 let span_len = before_tag.len() - cur.len();
466 view.__buffa_unknown_fields.push_raw(&before_tag[..span_len]);
467 }
468 }
469 }
470 ::core::result::Result::Ok(())
471 }
472}
473impl<'a> ::buffa::MessageView<'a> for AnyView<'a> {
474 type Owned = Any;
475 fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
476 Self::_decode_depth(buf, ::buffa::RECURSION_LIMIT)
477 }
478 fn decode_view_with_limit(
479 buf: &'a [u8],
480 depth: u32,
481 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
482 Self::_decode_depth(buf, depth)
483 }
484 /// Convert this view to the owned message type.
485 #[allow(clippy::redundant_closure, clippy::useless_conversion)]
486 fn to_owned_message(&self) -> Any {
487 #[allow(unused_imports)]
488 use ::buffa::alloc::string::ToString as _;
489 Any {
490 type_url: self.type_url.to_string(),
491 value: (self.value).to_vec(),
492 __buffa_unknown_fields: self
493 .__buffa_unknown_fields
494 .to_owned()
495 .unwrap_or_default()
496 .into(),
497 ..::core::default::Default::default()
498 }
499 }
500}
501unsafe impl ::buffa::DefaultViewInstance for AnyView<'static> {
502 fn default_view_instance() -> &'static Self {
503 static VALUE: ::buffa::__private::OnceBox<AnyView<'static>> = ::buffa::__private::OnceBox::new();
504 VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
505 }
506}
507unsafe impl<'a> ::buffa::HasDefaultViewInstance for AnyView<'a> {
508 type Static = AnyView<'static>;
509}