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

/** Lazy view of `sf.substreams.index.v1.Keys`: nested and repeated message fields are
 recorded as undecoded byte ranges and decoded on access. See
 [`::buffa::LazyMessageView`] for the deferred-validation contract;
 the eager, whole-tree-validated counterpart is named `KeysView`.

 Oneof variants, map values, groups, and extern-typed fields (e.g.
 well-known types) hold eagerly-decoded `KeysView`-family
 types; only singular/repeated message fields defer.

 # Examples

 ```rust,ignore
 use buffa::LazyMessageView;

 let view = KeysLazyView::decode_lazy(&bytes)?;
 ```*/
#[derive(Clone, Debug, Default)]
pub struct KeysLazyView<'a> {
    /// Field 1: `keys`
    pub keys: ::buffa::RepeatedView<'a, &'a str>,
}
impl<'a> KeysLazyView<'a> {
    /// Decode from `buf` under the limits carried by `ctx`, recording
    /// nested/repeated message fields as byte ranges.
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _decode_lazy_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let mut view = Self::default();
        view._merge_lazy(buf, ctx)?;
        ::core::result::Result::Ok(view)
    }
    /// Merge fields from `buf` into this view (proto merge semantics;
    /// deferred message fragments accumulate).
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        let _ = ctx;
        #[allow(unused_variables)]
        let view = self;
        let mut cur: &'a [u8] = buf;
        while !cur.is_empty() {
            let tag = ::buffa::encoding::Tag::decode(&mut 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(())
    }
}
impl<'a> ::buffa::LazyMessageView<'a> for KeysLazyView<'a> {
    type Owned = super::super::Keys;
    fn decode_lazy(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::_decode_lazy_ctx(
            buf,
            ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit)
                .with_element_memory(&__elem),
        )
    }
    fn decode_lazy_with_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        Self::_decode_lazy_ctx(buf, ctx)
    }
    fn merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        self._merge_lazy(buf, ctx)
    }
    #[allow(clippy::useless_conversion, clippy::needless_update)]
    fn to_owned_message(
        &self,
    ) -> ::core::result::Result<super::super::Keys, ::buffa::DecodeError> {
        #[allow(unused_imports)]
        use ::buffa::alloc::string::ToString as _;
        #[allow(unused_imports)]
        use ::buffa::MessageView as _;
        let __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes> = ::core::option::Option::None;
        let _ = __buffa_src;
        ::core::result::Result::Ok(super::super::Keys {
            keys: self.keys.iter().map(|s| s.to_string()).collect(),
            ..::core::default::Default::default()
        })
    }
}
/// Re-encoding: recorded fragments are replayed byte-for-byte
/// **without validation** — wire-equivalent to the merged value, and
/// a never-accessed malformed deferred field round-trips silently.
/// Inherent rather than [`::buffa::ViewEncode`] (whose `MessageView`
/// supertrait carries the eager whole-tree-validated contract); the
/// fuller `ViewEncode` set (`encode_length_delimited`,
/// `encode_with_cache`) lives on the eager view.
impl<'a> KeysLazyView<'a> {
    /// Compute the encoded byte size, filling `cache` with
    /// per-message sizes consumed by a following `write_to` call.
    /// Called for that side effect by `encode`; prefer `encoded_len`
    /// when only the size is needed.
    #[allow(clippy::needless_borrow, clippy::let_and_return)]
    pub fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        let mut size = 0u64;
        for v in &self.keys {
            size += 1u64 + ::buffa::types::string_encoded_len(v) as u64;
        }
        ::buffa::saturate_size(size)
    }
    /// Write the encoded bytes to `buf`, reading per-message sizes
    /// from the `cache` filled by a preceding `compute_size` call.
    /// Prefer `encode` unless threading a shared cache.
    #[allow(clippy::needless_borrow)]
    pub fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::EncodeSink,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        for v in &self.keys {
            ::buffa::types::put_string_field(1u32, v, buf);
        }
    }
    /// Compute size, then write. Primary encode entry point.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode`](Self::try_encode) for the error-returning
    /// variant.
    #[inline]
    pub fn encode(&self, buf: &mut impl ::buffa::EncodeSink) {
        self.try_encode(buf).unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encode, returning an error instead of panicking if the
    /// encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// On `Err`, nothing is written to `buf`.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encode(
        &self,
        buf: &mut impl ::buffa::EncodeSink,
    ) -> ::core::result::Result<(), ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        ::buffa::checked_encode_size(self.compute_size(&mut __cache))?;
        self.write_to(&mut __cache, buf);
        ::core::result::Result::Ok(())
    }
    /// Encoded byte size of this view.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encoded_len`](Self::try_encoded_len) for the
    /// error-returning variant.
    #[inline]
    #[must_use]
    pub fn encoded_len(&self) -> u32 {
        self.try_encoded_len().unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encoded byte size, returning an error instead of panicking
    /// if it exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encoded_len(&self) -> ::core::result::Result<u32, ::buffa::EncodeError> {
        ::buffa::checked_encode_size(self.compute_size(&mut ::buffa::SizeCache::new()))
    }
    /// Encode this view to a new `Vec<u8>`.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_vec`](Self::try_encode_to_vec) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_vec(&self) -> ::buffa::alloc::vec::Vec<u8> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf
    }
    /// Encode to a new `Vec<u8>`, returning an error instead of
    /// panicking if the encoded size exceeds the 2 GiB protobuf
    /// limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_vec(
        &self,
    ) -> ::core::result::Result<::buffa::alloc::vec::Vec<u8>, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf)
    }
    /// Encode this view to a new [`::buffa::bytes::Bytes`].
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_bytes`](Self::try_encode_to_bytes) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_bytes(&self) -> ::buffa::bytes::Bytes {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf.freeze()
    }
    /// Encode to a new [`::buffa::bytes::Bytes`], returning an
    /// error instead of panicking if the encoded size exceeds the
    /// 2 GiB protobuf limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_bytes(
        &self,
    ) -> ::core::result::Result<::buffa::bytes::Bytes, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf.freeze())
    }
}
impl<'a> ::buffa::MessageName for KeysLazyView<'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";
}