// @generated by buffa-codegen. DO NOT EDIT.
// source: google/protobuf/any.proto

/// `Any` contains an arbitrary serialized protocol buffer message along with a
/// URL that describes the type of the serialized message.
///
/// Protobuf library provides support to pack/unpack Any values in the form
/// of utility functions or additional generated methods of the Any type.
///
/// Example 1: Pack and unpack a message in C++.
///
/// ```text
/// Foo foo = ...;
/// Any any;
/// any.PackFrom(foo);
/// ...
/// if (any.UnpackTo(&foo)) {
///   ...
/// }
/// ```
///
/// Example 2: Pack and unpack a message in Java.
///
/// ```text
/// Foo foo = ...;
/// Any any = Any.pack(foo);
/// ...
/// if (any.is(Foo.class)) {
///   foo = any.unpack(Foo.class);
/// }
/// // or ...
/// if (any.isSameTypeAs(Foo.getDefaultInstance())) {
///   foo = any.unpack(Foo.getDefaultInstance());
/// }
/// ```
///
///  Example 3: Pack and unpack a message in Python.
///
/// ```text
/// foo = Foo(...)
/// any = Any()
/// any.Pack(foo)
/// ...
/// if any.Is(Foo.DESCRIPTOR):
///   any.Unpack(foo)
///   ...
/// ```
///
///  Example 4: Pack and unpack a message in Go
///
/// ```text
///  foo := &pb.Foo{...}
///  any, err := anypb.New(foo)
///  if err != nil {
///    ...
///  }
///  ...
///  foo := &pb.Foo{}
///  if err := any.UnmarshalTo(foo); err != nil {
///    ...
///  }
/// ```
///
/// The pack methods provided by protobuf library will by default use
/// 'type.googleapis.com/full.type.name' as the type URL and the unpack
/// methods only use the fully qualified type name after the last '/'
/// in the type URL, for example "foo.bar.com/x/y.z" will yield type
/// name "y.z".
///
/// JSON
/// ====
/// The JSON representation of an `Any` value uses the regular
/// representation of the deserialized, embedded message, with an
/// additional field `@type` which contains the type URL. Example:
///
/// ```text
/// package google.profile;
/// message Person {
///   string first_name = 1;
///   string last_name = 2;
/// }
///
/// {
///   "@type": "type.googleapis.com/google.profile.Person",
///   "firstName": <string>,
///   "lastName": <string>
/// }
/// ```
///
/// If the embedded message type is well-known and has a custom JSON
/// representation, that representation will be embedded adding a field
/// `value` which holds the custom JSON in addition to the `@type`
/// field. Example (for message [google.protobuf.Duration](crate::google::protobuf::Duration)):
///
/// ```text
/// {
///   "@type": "type.googleapis.com/google.protobuf.Duration",
///   "value": "1.212s"
/// }
/// ```
#[derive(Clone, PartialEq, Default)]
#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
pub struct Any {
    /// A URL/resource name that uniquely identifies the type of the serialized
    /// protocol buffer message. This string must contain at least
    /// one "/" character. The last segment of the URL's path must represent
    /// the fully qualified name of the type (as in
    /// `path/google.protobuf.Duration`). The name should be in a canonical form
    /// (e.g., leading "." is not accepted).
    ///
    /// In practice, teams usually precompile into the binary all types that they
    /// expect it to use in the context of Any. However, for URLs which use the
    /// scheme `http`, `https`, or no scheme, one can optionally set up a type
    /// server that maps type URLs to message definitions as follows:
    ///
    /// * If no scheme is provided, `https` is assumed.
    /// * An HTTP GET on the URL must yield a \[google.protobuf.Type\]\[\]
    ///   value in binary format, or produce an error.
    /// * Applications are allowed to cache lookup results based on the
    ///   URL, or have them precompiled into a binary to avoid any
    ///   lookup. Therefore, binary compatibility needs to be preserved
    ///   on changes to types. (Use versioned type names to manage
    ///   breaking changes.)
    ///
    /// Note: this functionality is not currently available in the official
    /// protobuf release, and it is not used for type URLs beginning with
    /// type.googleapis.com. As of May 2023, there are no widely used type server
    /// implementations and no plans to implement one.
    ///
    /// Schemes other than `http`, `https` (or the empty scheme) might be
    /// used with implementation specific semantics.
    ///
    /// Field 1: `type_url`
    pub type_url: ::buffa::alloc::string::String,
    /// Must be a valid serialized protocol buffer of the above specified type.
    ///
    /// Field 2: `value`
    #[cfg_attr(
        feature = "arbitrary",
        arbitrary(with = ::buffa::__private::arbitrary_bytes)
    )]
    pub value: ::buffa::bytes::Bytes,
    #[doc(hidden)]
    pub __buffa_unknown_fields: ::buffa::UnknownFields,
}
impl ::core::fmt::Debug for Any {
    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        f.debug_struct("Any")
            .field("type_url", &self.type_url)
            .field("value", &self.value)
            .finish()
    }
}
impl Any {
    /// Protobuf type URL for this message, for use with `Any::pack` and
    /// `Any::unpack_if`.
    ///
    /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
    pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Any";
}
impl ::buffa::DefaultInstance for Any {
    fn default_instance() -> &'static Self {
        static VALUE: ::buffa::__private::OnceBox<Any> = ::buffa::__private::OnceBox::new();
        VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
    }
}
#[cfg(feature = "reflect")]
const _: () = {
    impl ::buffa_descriptor::reflect::ReflectMessage for Any {
        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
            __buffa::reflect::descriptor_pool()
                .message(Self::__buffa_reflect_message_index())
        }
        fn pool(
            &self,
        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
            __buffa::reflect::descriptor_pool()
        }
        fn unknown_fields(&self) -> &::buffa::UnknownFields {
            &self.__buffa_unknown_fields
        }
        fn get(
            &self,
            field: &::buffa_descriptor::FieldDescriptor,
        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
            #[allow(unused_imports)]
            use ::buffa::Enumeration as _;
            match field.number() {
                1u32 => ::buffa_descriptor::reflect::ValueRef::String(&self.type_url),
                2u32 => ::buffa_descriptor::reflect::ValueRef::Bytes(&self.value[..]),
                _ => {
                    ::core::debug_assert!(
                        false,
                        "field number {} is not a member of this message's reflect get()",
                        field.number(),
                    );
                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
                }
            }
        }
        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
            match field.number() {
                1u32 => !self.type_url.is_empty(),
                2u32 => !self.value.is_empty(),
                _ => false,
            }
        }
        fn for_each_set(
            &self,
            f: &mut dyn ::core::ops::FnMut(
                &::buffa_descriptor::FieldDescriptor,
                ::buffa_descriptor::reflect::ValueRef<'_>,
            ),
        ) {
            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
                self,
            );
            for fd in md.fields() {
                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
                }
            }
        }
        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
            ::buffa_descriptor::reflect::DynamicMessage::from_message(
                self,
                ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
                Self::__buffa_reflect_message_index(),
            )
        }
    }
    impl ::buffa_descriptor::reflect::ReflectElement for Any {
        #[inline]
        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
            ::buffa_descriptor::reflect::ValueRef::Message(
                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
            )
        }
    }
    impl Any {
        /// Memoized `MessageIndex` for this message type, resolved once
        /// against the package's embedded descriptor pool.
        #[doc(hidden)]
        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
            *IDX
                .get_or_init(|| {
                    __buffa::reflect::descriptor_pool()
                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
                        .expect(
                            "generated message is registered in the embedded descriptor pool",
                        )
                })
        }
    }
    impl ::buffa_descriptor::reflect::Reflectable for Any {
        /// Vtable-mode reflective handle: borrows `self` directly. No
        /// encode/decode round-trip and no allocation — the reflective
        /// accessors read this message's fields in place.
        #[inline]
        fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
            ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
        }
    }
};
impl ::buffa::MessageName for Any {
    const PACKAGE: &'static str = "google.protobuf";
    const NAME: &'static str = "Any";
    const FULL_NAME: &'static str = "google.protobuf.Any";
    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Any";
}
impl ::buffa::Message for Any {
    /// Returns the total encoded size in bytes.
    ///
    /// The result is a `u32`; the protobuf specification requires all
    /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
    /// compliant message will never overflow this type.
    #[allow(clippy::let_and_return)]
    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        let mut size = 0u32;
        if !self.type_url.is_empty() {
            size += 1u32 + ::buffa::types::string_encoded_len(&self.type_url) as u32;
        }
        if !self.value.is_empty() {
            size += 1u32 + ::buffa::types::bytes_encoded_len(&self.value) as u32;
        }
        size += self.__buffa_unknown_fields.encoded_len() as u32;
        size
    }
    fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::bytes::BufMut,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        if !self.type_url.is_empty() {
            ::buffa::encoding::Tag::new(
                    1u32,
                    ::buffa::encoding::WireType::LengthDelimited,
                )
                .encode(buf);
            ::buffa::types::encode_string(&self.type_url, buf);
        }
        if !self.value.is_empty() {
            ::buffa::encoding::Tag::new(
                    2u32,
                    ::buffa::encoding::WireType::LengthDelimited,
                )
                .encode(buf);
            ::buffa::types::encode_bytes(&self.value, buf);
        }
        self.__buffa_unknown_fields.write_to(buf);
    }
    fn merge_field(
        &mut self,
        tag: ::buffa::encoding::Tag,
        buf: &mut impl ::buffa::bytes::Buf,
        depth: u32,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        #[allow(unused_imports)]
        use ::buffa::bytes::Buf as _;
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        match tag.field_number() {
            1u32 => {
                if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
                        field_number: 1u32,
                        expected: 2u8,
                        actual: tag.wire_type() as u8,
                    });
                }
                ::buffa::types::merge_string(&mut self.type_url, buf)?;
            }
            2u32 => {
                if tag.wire_type() != ::buffa::encoding::WireType::LengthDelimited {
                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
                        field_number: 2u32,
                        expected: 2u8,
                        actual: tag.wire_type() as u8,
                    });
                }
                self.value = ::buffa::types::decode_bytes_to_bytes(buf)?;
            }
            _ => {
                self.__buffa_unknown_fields
                    .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
            }
        }
        ::core::result::Result::Ok(())
    }
    fn clear(&mut self) {
        self.type_url.clear();
        self.value = ::buffa::bytes::Bytes::new();
        self.__buffa_unknown_fields.clear();
    }
}
impl ::buffa::ExtensionSet for Any {
    const PROTO_FQN: &'static str = "google.protobuf.Any";
    fn unknown_fields(&self) -> &::buffa::UnknownFields {
        &self.__buffa_unknown_fields
    }
    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
        &mut self.__buffa_unknown_fields
    }
}
#[doc(hidden)]
pub const __ANY_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
    type_url: "type.googleapis.com/google.protobuf.Any",
    text_encode: ::buffa::type_registry::any_encode_text::<Any>,
    text_merge: ::buffa::type_registry::any_merge_text::<Any>,
};
