buffa_types/generated/google.protobuf.any.rs
1// @generated by buffa-codegen. 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](crate::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 #[cfg_attr(
139 feature = "arbitrary",
140 arbitrary(with = ::buffa::__private::arbitrary_bytes)
141 )]
142 pub value: ::buffa::bytes::Bytes,
143 #[doc(hidden)]
144 pub __buffa_unknown_fields: ::buffa::UnknownFields,
145}
146impl ::core::fmt::Debug for Any {
147 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
148 f.debug_struct("Any")
149 .field("type_url", &self.type_url)
150 .field("value", &self.value)
151 .finish()
152 }
153}
154impl Any {
155 /// Protobuf type URL for this message, for use with `Any::pack` and
156 /// `Any::unpack_if`.
157 ///
158 /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
159 pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Any";
160}
161impl ::buffa::DefaultInstance for Any {
162 fn default_instance() -> &'static Self {
163 static VALUE: ::buffa::__private::OnceBox<Any> = ::buffa::__private::OnceBox::new();
164 VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
165 }
166}
167#[cfg(feature = "reflect")]
168const _: () = {
169 impl ::buffa_descriptor::reflect::ReflectMessage for Any {
170 fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
171 __buffa::reflect::descriptor_pool()
172 .message(Self::__buffa_reflect_message_index())
173 }
174 fn pool(
175 &self,
176 ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
177 __buffa::reflect::descriptor_pool()
178 }
179 fn unknown_fields(&self) -> &::buffa::UnknownFields {
180 &self.__buffa_unknown_fields
181 }
182 fn get(
183 &self,
184 field: &::buffa_descriptor::FieldDescriptor,
185 ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
186 #[allow(unused_imports)]
187 use ::buffa::Enumeration as _;
188 match field.number() {
189 1u32 => ::buffa_descriptor::reflect::ValueRef::String(&self.type_url),
190 2u32 => ::buffa_descriptor::reflect::ValueRef::Bytes(&self.value[..]),
191 _ => {
192 ::core::debug_assert!(
193 false,
194 "field number {} is not a member of this message's reflect get()",
195 field.number(),
196 );
197 ::buffa_descriptor::reflect::ValueRef::Bool(false)
198 }
199 }
200 }
201 fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
202 match field.number() {
203 1u32 => !self.type_url.is_empty(),
204 2u32 => !self.value.is_empty(),
205 _ => false,
206 }
207 }
208 fn for_each_set(
209 &self,
210 f: &mut dyn ::core::ops::FnMut(
211 &::buffa_descriptor::FieldDescriptor,
212 ::buffa_descriptor::reflect::ValueRef<'_>,
213 ),
214 ) {
215 let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
216 self,
217 );
218 for fd in md.fields() {
219 if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
220 f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
221 }
222 }
223 }
224 fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
225 ::buffa_descriptor::reflect::DynamicMessage::from_message(
226 self,
227 ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
228 Self::__buffa_reflect_message_index(),
229 )
230 }
231 }
232 impl ::buffa_descriptor::reflect::ReflectElement for Any {
233 fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
234 ::buffa_descriptor::reflect::ValueRef::Message(
235 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
236 )
237 }
238 }
239 impl Any {
240 /// Memoized `MessageIndex` for this message type, resolved once
241 /// against the package's embedded descriptor pool.
242 #[doc(hidden)]
243 fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
244 static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
245 *IDX
246 .get_or_init(|| {
247 __buffa::reflect::descriptor_pool()
248 .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
249 .expect(
250 "generated message is registered in the embedded descriptor pool",
251 )
252 })
253 }
254 }
255 impl ::buffa_descriptor::reflect::Reflectable for Any {
256 /// Vtable-mode reflective handle: borrows `self` directly. No
257 /// encode/decode round-trip and no allocation — the reflective
258 /// accessors read this message's fields in place.
259 fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
260 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
261 }
262 }
263};
264impl ::buffa::MessageName for Any {
265 const PACKAGE: &'static str = "google.protobuf";
266 const NAME: &'static str = "Any";
267 const FULL_NAME: &'static str = "google.protobuf.Any";
268 const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Any";
269}
270impl ::buffa::Message for Any {
271 /// Returns the total encoded size in bytes.
272 ///
273 /// The result is a `u32`; the protobuf specification requires all
274 /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
275 /// compliant message will never overflow this type.
276 #[allow(clippy::let_and_return)]
277 fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
278 #[allow(unused_imports)]
279 use ::buffa::Enumeration as _;
280 let mut size = 0u32;
281 if !self.type_url.is_empty() {
282 size += 1u32 + ::buffa::types::string_encoded_len(&self.type_url) as u32;
283 }
284 if !self.value.is_empty() {
285 size += 1u32 + ::buffa::types::bytes_encoded_len(&self.value) as u32;
286 }
287 size += self.__buffa_unknown_fields.encoded_len() as u32;
288 size
289 }
290 fn write_to(
291 &self,
292 _cache: &mut ::buffa::SizeCache,
293 buf: &mut impl ::buffa::bytes::BufMut,
294 ) {
295 #[allow(unused_imports)]
296 use ::buffa::Enumeration as _;
297 if !self.type_url.is_empty() {
298 ::buffa::encoding::Tag::new(
299 1u32,
300 ::buffa::encoding::WireType::LengthDelimited,
301 )
302 .encode(buf);
303 ::buffa::types::encode_string(&self.type_url, buf);
304 }
305 if !self.value.is_empty() {
306 ::buffa::encoding::Tag::new(
307 2u32,
308 ::buffa::encoding::WireType::LengthDelimited,
309 )
310 .encode(buf);
311 ::buffa::types::encode_bytes(&self.value, buf);
312 }
313 self.__buffa_unknown_fields.write_to(buf);
314 }
315 fn merge_field(
316 &mut self,
317 tag: ::buffa::encoding::Tag,
318 buf: &mut impl ::buffa::bytes::Buf,
319 depth: u32,
320 ) -> ::core::result::Result<(), ::buffa::DecodeError> {
321 #[allow(unused_imports)]
322 use ::buffa::bytes::Buf as _;
323 #[allow(unused_imports)]
324 use ::buffa::Enumeration as _;
325 match tag.field_number() {
326 1u32 => {
327 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
328 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
329 field_number: 1u32,
330 expected: 2u8,
331 actual: tag.wire_type() as u8,
332 });
333 }
334 ::buffa::types::merge_string(&mut self.type_url, buf)?;
335 }
336 2u32 => {
337 if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
338 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
339 field_number: 2u32,
340 expected: 2u8,
341 actual: tag.wire_type() as u8,
342 });
343 }
344 self.value = ::buffa::types::decode_bytes_to_bytes(buf)?;
345 }
346 _ => {
347 self.__buffa_unknown_fields
348 .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
349 }
350 }
351 ::core::result::Result::Ok(())
352 }
353 fn clear(&mut self) {
354 self.type_url.clear();
355 self.value = ::buffa::bytes::Bytes::new();
356 self.__buffa_unknown_fields.clear();
357 }
358}
359impl ::buffa::ExtensionSet for Any {
360 const PROTO_FQN: &'static str = "google.protobuf.Any";
361 fn unknown_fields(&self) -> &::buffa::UnknownFields {
362 &self.__buffa_unknown_fields
363 }
364 fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
365 &mut self.__buffa_unknown_fields
366 }
367}
368#[doc(hidden)]
369pub const __ANY_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
370 type_url: "type.googleapis.com/google.protobuf.Any",
371 text_encode: ::buffa::type_registry::any_encode_text::<Any>,
372 text_merge: ::buffa::type_registry::any_merge_text::<Any>,
373};