Decoder

Trait Decoder 

Source
pub trait Decoder: Sized {
    type Output;
    type Error;

    // Required methods
    fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error>;
    fn end(self) -> Result<Self::Output, Self::Error>;
    fn read_limit(&self) -> usize;
}
Expand description

A push decoder for a consensus-decodable object.

Required Associated Types§

Source

type Output

The type that this decoder produces when decoding is complete.

Source

type Error

The error type that this decoder can produce.

Required Methods§

Source

fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error>

Push bytes into the decoder, consuming as much as possible.

The slice reference will be advanced to point to the unconsumed portion. Returns Ok(true) if more bytes are needed to complete decoding, Ok(false) if the decoder is ready to finalize with Self::end, or Err(error) if parsing failed.

§Errors

Returns an error if the provided bytes are invalid or malformed according to the decoder’s validation rules. Insufficient data (needing more bytes) is not an error for this method, the decoder will simply consume what it can and return true to indicate more data is needed.

§Panics

May panic if called after a previous call to Self::push_bytes errored.

Source

fn end(self) -> Result<Self::Output, Self::Error>

Complete the decoding process and return the final result.

This consumes the decoder and should be called when no more input data is available.

§Errors

Returns an error if the decoder has not received sufficient data to complete decoding, or if the accumulated data is invalid when considered as a complete object.

§Panics

May panic if called after a previous call to Self::push_bytes errored.

Source

fn read_limit(&self) -> usize

Returns the maximum number of bytes this decoder can consume without over-reading.

Returns 0 if the decoder is complete and ready to finalize with Self::end. This is used by decode_from_read_unbuffered to optimize read sizes, avoiding both inefficient under-reads and unnecessary over-reads.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Decoder for ByteVecDecoder

Available on crate feature alloc only.
Source§

impl Decoder for CompactSizeDecoder

Source§

impl<A, B> Decoder for Decoder2<A, B>
where A: Decoder, B: Decoder,

Source§

type Output = (<A as Decoder>::Output, <B as Decoder>::Output)

Source§

type Error = Decoder2Error<<A as Decoder>::Error, <B as Decoder>::Error>

Source§

impl<A, B, C> Decoder for Decoder3<A, B, C>
where A: Decoder, B: Decoder, C: Decoder,

Source§

type Output = (<A as Decoder>::Output, <B as Decoder>::Output, <C as Decoder>::Output)

Source§

type Error = Decoder3Error<<A as Decoder>::Error, <B as Decoder>::Error, <C as Decoder>::Error>

Source§

impl<A, B, C, D> Decoder for Decoder4<A, B, C, D>
where A: Decoder, B: Decoder, C: Decoder, D: Decoder,

Source§

type Output = (<A as Decoder>::Output, <B as Decoder>::Output, <C as Decoder>::Output, <D as Decoder>::Output)

Source§

type Error = Decoder4Error<<A as Decoder>::Error, <B as Decoder>::Error, <C as Decoder>::Error, <D as Decoder>::Error>

Source§

impl<A, B, C, D, E, F> Decoder for Decoder6<A, B, C, D, E, F>
where A: Decoder, B: Decoder, C: Decoder, D: Decoder, E: Decoder, F: Decoder,

Source§

type Output = (<A as Decoder>::Output, <B as Decoder>::Output, <C as Decoder>::Output, <D as Decoder>::Output, <E as Decoder>::Output, <F as Decoder>::Output)

Source§

type Error = Decoder6Error<<A as Decoder>::Error, <B as Decoder>::Error, <C as Decoder>::Error, <D as Decoder>::Error, <E as Decoder>::Error, <F as Decoder>::Error>

Source§

impl<T: Decodable> Decoder for VecDecoder<T>

Available on crate feature alloc only.
Source§

impl<const N: usize> Decoder for ArrayDecoder<N>