pub trait Decode {
// Required method
fn decode(data: &mut &[u8]) -> Result<Self, DecodeError>
where Self: Sized;
}
Expand description
A type that can be reconstructed (decoded) from a raw sequence of bytes.
Implementors of this trait define how to parse their binary representation from an input buffer. The input slice will be advanced by the number of bytes successfully consumed during decoding.
Required Methods§
Sourcefn decode(data: &mut &[u8]) -> Result<Self, DecodeError>where
Self: Sized,
fn decode(data: &mut &[u8]) -> Result<Self, DecodeError>where
Self: Sized,
Attempts to decode Self
from the beginning of the provided byte slice.
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.