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§
Required Methods§
Sourcefn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error>
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.
Sourcefn end(self) -> Result<Self::Output, Self::Error>
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.
Sourcefn read_limit(&self) -> usize
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.
impl Decoder for ByteVecDecoder
alloc only.Source§impl Decoder for CompactSizeDecoder
impl Decoder for CompactSizeDecoder
Source§impl<A, B, C, D, E, F> Decoder for Decoder6<A, B, C, D, E, F>
impl<A, B, C, D, E, F> Decoder for Decoder6<A, B, C, D, E, F>
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)
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.
impl<T: Decodable> Decoder for VecDecoder<T>
alloc only.