substreams 0.8.0-beta

Substreams SDK - A streaming data engine for The Graph - by StreamingFast
Documentation
// @generated by buffa-codegen. DO NOT EDIT.
// source: sf/substreams/index/v1/keys.proto

#[derive(Clone, Debug, Default)]
pub struct KeysView<'a> {
    /// Field 1: `keys`
    pub keys: ::buffa::RepeatedView<'a, &'a str>,
}
impl<'a> ::buffa::MessageView<'a> for KeysView<'a> {
    type Owned = super::super::Keys;
    fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
        let __elem = ::core::cell::Cell::new(::buffa::DEFAULT_ELEMENT_MEMORY_LIMIT);
        <Self as ::buffa::MessageView>::decode_view_ctx(
            buf,
            ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit)
                .with_element_memory(&__elem),
        )
    }
    fn decode_view_with_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        <Self as ::buffa::MessageView>::decode_view_ctx(buf, ctx)
    }
    #[inline]
    fn merge_view_field(
        &mut self,
        tag: ::buffa::encoding::Tag,
        cur: &'a [u8],
        _before_tag: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<&'a [u8], ::buffa::DecodeError> {
        let _ = ctx;
        #[allow(unused_variables)]
        let view = self;
        let mut cur = cur;
        match tag.field_number() {
            1u32 => {
                ::buffa::encoding::check_wire_type(
                    tag,
                    ::buffa::encoding::WireType::LengthDelimited,
                )?;
                let __elem = ::buffa::types::borrow_str(&mut cur)?;
                ctx.register_element_memory(
                    ::buffa::__private::element_footprint(&__elem),
                )?;
                view.keys.push(__elem);
            }
            _ => {
                ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
            }
        }
        ::core::result::Result::Ok(cur)
    }
    fn to_owned_message(
        &self,
    ) -> ::core::result::Result<super::super::Keys, ::buffa::DecodeError> {
        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>,
    ) -> ::core::result::Result<super::super::Keys, ::buffa::DecodeError> {
        #[allow(unused_imports)]
        use ::buffa::alloc::string::ToString as _;
        let _ = __buffa_src;
        ::core::result::Result::Ok(super::super::Keys {
            keys: self.keys.iter().map(|s| s.to_string()).collect(),
            ..::core::default::Default::default()
        })
    }
}
impl<'a> ::buffa::ViewEncode<'a> for KeysView<'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 = 0u64;
        for v in &self.keys {
            size += 1u64 + ::buffa::types::string_encoded_len(v) as u64;
        }
        ::buffa::saturate_size(size)
    }
    #[allow(clippy::needless_borrow)]
    fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::EncodeSink,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        for v in &self.keys {
            ::buffa::types::put_string_field(1u32, v, buf);
        }
    }
}
impl<'a> ::buffa::MessageName for KeysView<'a> {
    const PACKAGE: &'static str = "sf.substreams.index.v1";
    const NAME: &'static str = "Keys";
    const FULL_NAME: &'static str = "sf.substreams.index.v1.Keys";
    const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.index.v1.Keys";
}
::buffa::impl_default_view_instance!(KeysView);
::buffa::impl_view_reborrow!(KeysView);
/** Self-contained, `'static` owned view of a `Keys` message.

 Wraps [`::buffa::OwnedView`]`<`[`KeysView`]`<'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 [`KeysView`] when you need struct patterns, iteration helpers, or to pass the view to lifetime-parameterised code.*/
#[derive(Clone, Debug)]
pub struct KeysOwnedView(::buffa::OwnedView<KeysView<'static>>);
impl KeysOwnedView {
    /// 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(KeysOwnedView(::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(
            KeysOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
        )
    }
    /// Build from an owned message via an encode → decode round-trip.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::DecodeError::MessageTooLarge`] if the
    /// message's encoded size exceeds the 2 GiB protobuf limit, or
    /// another [`::buffa::DecodeError`] if the re-encoded bytes are
    /// somehow invalid (should not happen for well-formed messages).
    pub fn from_owned(
        msg: &super::super::Keys,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        ::core::result::Result::Ok(KeysOwnedView(::buffa::OwnedView::from_owned(msg)?))
    }
    /// Borrow the full [`KeysView`] with its lifetime tied to `&self`.
    #[must_use]
    pub fn view(&self) -> &KeysView<'_> {
        self.0.reborrow()
    }
    /// Convert to the owned message type.
    ///
    /// Infallible: this type's constructors wire-decode their
    /// buffer, and a view produced by wire decoding always
    /// converts. Delegates to [`::buffa::OwnedView::to_owned_message`],
    /// whose contract also governs handles converted from a raw
    /// [`::buffa::OwnedView`].
    #[must_use]
    pub fn to_owned_message(&self) -> super::super::Keys {
        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()
    }
    /// Field 1: `keys`
    #[must_use]
    pub fn keys(&self) -> &::buffa::RepeatedView<'_, &'_ str> {
        &self.0.reborrow().keys
    }
}
impl ::core::convert::From<::buffa::OwnedView<KeysView<'static>>> for KeysOwnedView {
    fn from(inner: ::buffa::OwnedView<KeysView<'static>>) -> Self {
        KeysOwnedView(inner)
    }
}
impl ::core::convert::From<KeysOwnedView> for ::buffa::OwnedView<KeysView<'static>> {
    fn from(wrapper: KeysOwnedView) -> Self {
        wrapper.0
    }
}
impl ::core::convert::AsRef<::buffa::OwnedView<KeysView<'static>>> for KeysOwnedView {
    fn as_ref(&self) -> &::buffa::OwnedView<KeysView<'static>> {
        &self.0
    }
}
impl ::buffa::HasMessageView for super::super::Keys {
    type View<'a> = KeysView<'a>;
    type ViewHandle = KeysOwnedView;
}