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

/// `FieldMask` represents a set of symbolic field paths, for example:
///
/// ```text
/// paths: "f.a"
/// paths: "f.b.d"
/// ```
///
/// Here `f` represents a field in some root message, `a` and `b`
/// fields in the message found in `f`, and `d` a field found in the
/// message in `f.b`.
///
/// Field masks are used to specify a subset of fields that should be
/// returned by a get operation or modified by an update operation.
/// Field masks also have a custom JSON encoding (see below).
///
/// # Field Masks in Projections
///
/// When used in the context of a projection, a response message or
/// sub-message is filtered by the API to only contain those fields as
/// specified in the mask. For example, if the mask in the previous
/// example is applied to a response message as follows:
///
/// ```text
/// f {
///   a : 22
///   b {
///     d : 1
///     x : 2
///   }
///   y : 13
/// }
/// z: 8
/// ```
///
/// The result will not contain specific values for fields x,y and z
/// (their value will be set to the default, and omitted in proto text
/// output):
///
///
/// ```text
/// f {
///   a : 22
///   b {
///     d : 1
///   }
/// }
/// ```
///
/// A repeated field is not allowed except at the last position of a
/// paths string.
///
/// If a FieldMask object is not present in a get operation, the
/// operation applies to all fields (as if a FieldMask of all fields
/// had been specified).
///
/// Note that a field mask does not necessarily apply to the
/// top-level response message. In case of a REST get operation, the
/// field mask applies directly to the response, but in case of a REST
/// list operation, the mask instead applies to each individual message
/// in the returned resource list. In case of a REST custom method,
/// other definitions may be used. Where the mask applies will be
/// clearly documented together with its declaration in the API.  In
/// any case, the effect on the returned resource/resources is required
/// behavior for APIs.
///
/// # Field Masks in Update Operations
///
/// A field mask in update operations specifies which fields of the
/// targeted resource are going to be updated. The API is required
/// to only change the values of the fields as specified in the mask
/// and leave the others untouched. If a resource is passed in to
/// describe the updated values, the API ignores the values of all
/// fields not covered by the mask.
///
/// If a repeated field is specified for an update operation, new values will
/// be appended to the existing repeated field in the target resource. Note that
/// a repeated field is only allowed in the last position of a `paths` string.
///
/// If a sub-message is specified in the last position of the field mask for an
/// update operation, then new value will be merged into the existing sub-message
/// in the target resource.
///
/// For example, given the target message:
///
/// ```text
/// f {
///   b {
///     d: 1
///     x: 2
///   }
///   c: [1]
/// }
/// ```
///
/// And an update message:
///
/// ```text
/// f {
///   b {
///     d: 10
///   }
///   c: [2]
/// }
/// ```
///
/// then if the field mask is:
///
///  paths: \["f.b", "f.c"\]
///
/// then the result will be:
///
/// ```text
/// f {
///   b {
///     d: 10
///     x: 2
///   }
///   c: [1, 2]
/// }
/// ```
///
/// An implementation may provide options to override this default behavior for
/// repeated and message fields.
///
/// In order to reset a field's value to the default, the field must
/// be in the mask and set to the default value in the provided resource.
/// Hence, in order to reset all fields of a resource, provide a default
/// instance of the resource and set all fields in the mask, or do
/// not provide a mask as described below.
///
/// If a field mask is not present on update, the operation applies to
/// all fields (as if a field mask of all fields has been specified).
/// Note that in the presence of schema evolution, this may mean that
/// fields the client does not know and has therefore not filled into
/// the request will be reset to their default. If this is unwanted
/// behavior, a specific service may require a client to always specify
/// a field mask, producing an error if not.
///
/// As with get operations, the location of the resource which
/// describes the updated values in the request message depends on the
/// operation kind. In any case, the effect of the field mask is
/// required to be honored by the API.
///
/// ## Considerations for HTTP REST
///
/// The HTTP kind of an update operation which uses a field mask must
/// be set to PATCH instead of PUT in order to satisfy HTTP semantics
/// (PUT must only be used for full updates).
///
/// # JSON Encoding of Field Masks
///
/// In JSON, a field mask is encoded as a single string where paths are
/// separated by a comma. Fields name in each path are converted
/// to/from lower-camel naming conventions.
///
/// As an example, consider the following message declarations:
///
/// ```text
/// message Profile {
///   User user = 1;
///   Photo photo = 2;
/// }
/// message User {
///   string display_name = 1;
///   string address = 2;
/// }
/// ```
///
/// In proto a field mask for `Profile` may look as such:
///
/// ```text
/// mask {
///   paths: "user.display_name"
///   paths: "photo"
/// }
/// ```
///
/// In JSON, the same mask is represented as below:
///
/// ```text
/// {
///   mask: "user.displayName,photo"
/// }
/// ```
///
/// # Field Masks and Oneof Fields
///
/// Field masks treat fields in oneofs just as regular fields. Consider the
/// following message:
///
/// ```text
/// message SampleMessage {
///   oneof test_oneof {
///     string name = 4;
///     SubMessage sub_message = 9;
///   }
/// }
/// ```
///
/// The field mask can be:
///
/// ```text
/// mask {
///   paths: "name"
/// }
/// ```
///
/// Or:
///
/// ```text
/// mask {
///   paths: "sub_message"
/// }
/// ```
///
/// Note that oneof type names ("test_oneof" in this case) cannot be used in
/// paths.
///
/// ## Field Mask Verification
///
/// The implementation of any API method which has a FieldMask type field in the
/// request should verify the included field paths, and return an
/// `INVALID_ARGUMENT` error if any path is unmappable.
#[derive(Clone, Debug, Default)]
pub struct FieldMaskView<'a> {
    /// The set of field mask paths.
    ///
    /// Field 1: `paths`
    pub paths: ::buffa::RepeatedView<'a, &'a str>,
    pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
}
impl<'a> FieldMaskView<'a> {
    /// Decode from `buf`, enforcing a recursion depth limit for nested messages.
    ///
    /// Called by [`::buffa::MessageView::decode_view`] with [`::buffa::RECURSION_LIMIT`]
    /// and by generated sub-message decode arms with `depth - 1`.
    ///
    /// **Not part of the public API.** Named with a leading underscore to
    /// signal that it is for generated-code use only.
    #[doc(hidden)]
    pub fn _decode_depth(
        buf: &'a [u8],
        depth: u32,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let mut view = Self::default();
        view._merge_into_view(buf, depth)?;
        ::core::result::Result::Ok(view)
    }
    /// Merge fields from `buf` into this view (proto merge semantics).
    ///
    /// Repeated fields append; singular fields last-wins; singular
    /// MESSAGE fields merge recursively. Used by sub-message decode
    /// arms when the same field appears multiple times on the wire.
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _merge_into_view(
        &mut self,
        buf: &'a [u8],
        depth: u32,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        let _ = depth;
        #[allow(unused_variables)]
        let view = self;
        let mut cur: &'a [u8] = buf;
        while !cur.is_empty() {
            let before_tag = cur;
            let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
            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,
                        });
                    }
                    view.paths.push(::buffa::types::borrow_str(&mut cur)?);
                }
                _ => {
                    ::buffa::encoding::skip_field_depth(tag, &mut cur, depth)?;
                    let span_len = before_tag.len() - cur.len();
                    view.__buffa_unknown_fields.push_raw(&before_tag[..span_len]);
                }
            }
        }
        ::core::result::Result::Ok(())
    }
}
impl<'a> ::buffa::MessageView<'a> for FieldMaskView<'a> {
    type Owned = super::super::FieldMask;
    fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        Self::_decode_depth(buf, ::buffa::RECURSION_LIMIT)
    }
    fn decode_view_with_limit(
        buf: &'a [u8],
        depth: u32,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        Self::_decode_depth(buf, depth)
    }
    fn to_owned_message(&self) -> super::super::FieldMask {
        self.to_owned_from_source(None)
    }
    #[allow(clippy::useless_conversion, clippy::needless_update)]
    fn to_owned_from_source(
        &self,
        __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
    ) -> super::super::FieldMask {
        #[allow(unused_imports)]
        use ::buffa::alloc::string::ToString as _;
        let _ = __buffa_src;
        super::super::FieldMask {
            paths: self.paths.iter().map(|s| s.to_string()).collect(),
            __buffa_unknown_fields: self
                .__buffa_unknown_fields
                .to_owned()
                .unwrap_or_default()
                .into(),
            ..::core::default::Default::default()
        }
    }
}
impl<'a> ::buffa::ViewEncode<'a> for FieldMaskView<'a> {
    #[allow(clippy::needless_borrow, clippy::let_and_return)]
    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        let mut size = 0u32;
        for v in &self.paths {
            size += 1u32 + ::buffa::types::string_encoded_len(v) as u32;
        }
        size += self.__buffa_unknown_fields.encoded_len() as u32;
        size
    }
    #[allow(clippy::needless_borrow)]
    fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::bytes::BufMut,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        for v in &self.paths {
            ::buffa::encoding::Tag::new(
                    1u32,
                    ::buffa::encoding::WireType::LengthDelimited,
                )
                .encode(buf);
            ::buffa::types::encode_string(v, buf);
        }
        self.__buffa_unknown_fields.write_to(buf);
    }
}
impl<'a> ::buffa::MessageName for FieldMaskView<'a> {
    const PACKAGE: &'static str = "google.protobuf";
    const NAME: &'static str = "FieldMask";
    const FULL_NAME: &'static str = "google.protobuf.FieldMask";
    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.FieldMask";
}
impl<'v> ::buffa::DefaultViewInstance for FieldMaskView<'v> {
    fn default_view_instance<'a>() -> &'a Self
    where
        Self: 'a,
    {
        static VALUE: ::buffa::__private::OnceBox<FieldMaskView<'static>> = ::buffa::__private::OnceBox::new();
        VALUE
            .get_or_init(|| ::buffa::alloc::boxed::Box::new(
                <FieldMaskView<'static>>::default(),
            ))
    }
}
impl ::buffa::ViewReborrow for FieldMaskView<'static> {
    type Reborrowed<'b> = FieldMaskView<'b>;
    fn reborrow<'b>(this: &'b Self) -> &'b Self::Reborrowed<'b> {
        this
    }
}
/** Self-contained, `'static` owned view of a `FieldMask` message.

 Wraps [`::buffa::OwnedView`]`<`[`FieldMaskView`]`<'static>>`: the decoded view and the [`::buffa::bytes::Bytes`] buffer it borrows from travel together, so the handle is `'static` and `Send + Sync` — suitable for async handlers, spawned tasks, and anywhere a `'static` bound is required.

 Field accessors return borrows tied to `&self`. Use [`Self::view`] to get the full [`FieldMaskView`] when you need struct patterns, iteration helpers, or to pass the view to lifetime-parameterised code.*/
#[derive(Clone, Debug)]
pub struct FieldMaskOwnedView(::buffa::OwnedView<FieldMaskView<'static>>);
impl FieldMaskOwnedView {
    /// Decode an owned view from a [`::buffa::bytes::Bytes`] buffer.
    ///
    /// The view borrows directly from the buffer's data; the buffer is
    /// retained inside the returned handle.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::DecodeError`] if the buffer contains invalid
    /// protobuf data.
    pub fn decode(
        bytes: ::buffa::bytes::Bytes,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        ::core::result::Result::Ok(
            FieldMaskOwnedView(::buffa::OwnedView::decode(bytes)?),
        )
    }
    /// Decode with custom [`::buffa::DecodeOptions`] (recursion limit,
    /// max message size).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::DecodeError`] if the buffer is invalid or
    /// exceeds the configured limits.
    pub fn decode_with_options(
        bytes: ::buffa::bytes::Bytes,
        opts: &::buffa::DecodeOptions,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        ::core::result::Result::Ok(
            FieldMaskOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
        )
    }
    /// Build from an owned message via an encode → decode round-trip.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::DecodeError`] if the re-encoded bytes are
    /// somehow invalid (should not happen for well-formed messages).
    pub fn from_owned(
        msg: &super::super::FieldMask,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        ::core::result::Result::Ok(
            FieldMaskOwnedView(::buffa::OwnedView::from_owned(msg)?),
        )
    }
    /// Borrow the full [`FieldMaskView`] with its lifetime tied to `&self`.
    #[must_use]
    pub fn view(&self) -> &FieldMaskView<'_> {
        self.0.reborrow()
    }
    /// Convert to the owned message type.
    #[must_use]
    pub fn to_owned_message(&self) -> super::super::FieldMask {
        self.0.to_owned_message()
    }
    /// The underlying bytes buffer.
    #[must_use]
    pub fn bytes(&self) -> &::buffa::bytes::Bytes {
        self.0.bytes()
    }
    /// Consume the handle, returning the underlying bytes buffer.
    #[must_use]
    pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
        self.0.into_bytes()
    }
    /// The set of field mask paths.
    ///
    /// Field 1: `paths`
    #[must_use]
    pub fn paths(&self) -> &::buffa::RepeatedView<'_, &'_ str> {
        &self.0.reborrow().paths
    }
}
impl ::core::convert::From<::buffa::OwnedView<FieldMaskView<'static>>>
for FieldMaskOwnedView {
    fn from(inner: ::buffa::OwnedView<FieldMaskView<'static>>) -> Self {
        FieldMaskOwnedView(inner)
    }
}
impl ::core::convert::From<FieldMaskOwnedView>
for ::buffa::OwnedView<FieldMaskView<'static>> {
    fn from(wrapper: FieldMaskOwnedView) -> Self {
        wrapper.0
    }
}
impl ::core::convert::AsRef<::buffa::OwnedView<FieldMaskView<'static>>>
for FieldMaskOwnedView {
    fn as_ref(&self) -> &::buffa::OwnedView<FieldMaskView<'static>> {
        &self.0
    }
}
impl ::buffa::HasMessageView for super::super::FieldMask {
    type View<'a> = FieldMaskView<'a>;
    type ViewHandle = FieldMaskOwnedView;
}
#[cfg(feature = "reflect")]
const _: () = {
    impl<'a> ::buffa_descriptor::reflect::ReflectMessage for FieldMaskView<'a> {
        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
            super::super::__buffa::reflect::descriptor_pool()
                .message(Self::__buffa_reflect_message_index())
        }
        fn pool(
            &self,
        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
            super::super::__buffa::reflect::descriptor_pool()
        }
        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::List(&self.paths),
                _ => {
                    ::core::debug_assert!(
                        false,
                        "field number {} is not a member of this view's reflect get()",
                        field.number(),
                    );
                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
                }
            }
        }
        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
            match field.number() {
                1u32 => !::buffa::RepeatedView::is_empty(&self.paths),
                _ => 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 {
            let bytes = ::buffa::ViewEncode::encode_to_vec(self);
            ::buffa_descriptor::reflect::DynamicMessage::decode(
                    ::buffa::alloc::sync::Arc::clone(
                        super::super::__buffa::reflect::descriptor_pool(),
                    ),
                    Self::__buffa_reflect_message_index(),
                    &bytes,
                )
                .expect("view re-encodes to bytes decodable against its own descriptor")
        }
    }
    impl<'a> ::buffa_descriptor::reflect::ReflectElement for FieldMaskView<'a> {
        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
            ::buffa_descriptor::reflect::ValueRef::Message(
                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
            )
        }
    }
    impl<'a> FieldMaskView<'a> {
        /// Memoized `MessageIndex` for this view's message type, resolved
        /// once against the package's embedded descriptor pool. An inherent
        /// associated fn (not a free fn) so sibling views in the same module
        /// do not collide.
        #[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(|| {
                    super::super::__buffa::reflect::descriptor_pool()
                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
                        .expect(
                            "generated view type is registered in the embedded descriptor pool",
                        )
                })
        }
    }
};
