multiversx_sc_codec/single/
nested_de_input.rs

1pub use crate::codec_err::DecodeError;
2use crate::{DecodeErrorHandler, TryStaticCast};
3
4/// Trait that allows deserializing objects from a buffer.
5pub trait NestedDecodeInput {
6    /// The remaining length of the input data.
7    fn remaining_len(&self) -> usize;
8
9    /// True if all data from the buffer has already been used.
10    fn is_depleted(&self) -> bool {
11        self.remaining_len() == 0
12    }
13
14    /// Read the exact number of bytes required to fill the given buffer, without consuming the underlying bytes.
15    ///
16    /// Will fail is not enough bytes left in buffer.
17    fn peek_into<H>(&mut self, into: &mut [u8], h: H) -> Result<(), H::HandledErr>
18    where
19        H: DecodeErrorHandler;
20
21    /// Read & consume the exact number of bytes required to fill the given buffer.
22    ///
23    /// Will fail is not enough bytes left in buffer.
24    fn read_into<H>(&mut self, into: &mut [u8], h: H) -> Result<(), H::HandledErr>
25    where
26        H: DecodeErrorHandler;
27
28    #[inline]
29    fn supports_specialized_type<T: TryStaticCast>() -> bool {
30        false
31    }
32
33    fn read_specialized<T, C, H>(&mut self, _context: C, h: H) -> Result<T, H::HandledErr>
34    where
35        T: TryStaticCast,
36        C: TryStaticCast,
37        H: DecodeErrorHandler,
38    {
39        Err(h.handle_error(DecodeError::UNSUPPORTED_OPERATION))
40    }
41
42    /// Read a single byte from the input.
43    fn read_byte<H>(&mut self, h: H) -> Result<u8, H::HandledErr>
44    where
45        H: DecodeErrorHandler,
46    {
47        let mut buf = [0u8];
48        self.read_into(&mut buf[..], h)?;
49        Ok(buf[0])
50    }
51}