pub trait DecodeWithLength {
// Required method
fn decode_with_len(
data: &mut &[u8],
len: usize,
) -> Result<Self, DecodeError>
where Self: Sized;
}
Expand description
A type that can be decoded from a sequence of bytes, given an indicator of the number of items contained within the type.
This is primarily intended for collection-like types (e.g. Vec
) whose
number of elements must be known before decoding can proceed. The caller
provides len
as the number of items expected to be decoded.
Like Decode
, the input slice will be advanced by the number of bytes
successfully consumed.
Required Methods§
Sourcefn decode_with_len(data: &mut &[u8], len: usize) -> Result<Self, DecodeError>where
Self: Sized,
fn decode_with_len(data: &mut &[u8], len: usize) -> Result<Self, DecodeError>where
Self: Sized,
Attempts to decode Self
from the provided byte slice, consuming exactly
len
items.
On success, returns the decoded value and advances data
by the number
of bytes consumed. On failure, returns a DecodeError
.
§Errors
Returns a DecodeError
if the input is malformed or insufficient
to decode a complete value of this type.