pub trait Decodable<'a>: Sized {
// Required methods
fn get_structure(data: &[u8]) -> Result<Vec<FieldMarker>, Error>;
fn from_decoded_fields(data: Vec<DecodableField<'a>>) -> Result<Self, Error>;
// Provided method
fn from_bytes(data: &'a mut [u8]) -> Result<Self, Error> { ... }
}Expand description
Custom deserialization of types from binary data.
Defines the process of reconstructing a type from a sequence of bytes. It handles both simple and nested or complex data structures.
Required Methods§
Sourcefn get_structure(data: &[u8]) -> Result<Vec<FieldMarker>, Error>
fn get_structure(data: &[u8]) -> Result<Vec<FieldMarker>, Error>
Defines the expected structure of a type based on binary data.
Returns a vector of FieldMarkers, each representing a component of the structure.
Useful for guiding the decoding process.
Sourcefn from_decoded_fields(data: Vec<DecodableField<'a>>) -> Result<Self, Error>
fn from_decoded_fields(data: Vec<DecodableField<'a>>) -> Result<Self, Error>
Constructs the type from a vector of decoded fields.
After the data has been split into fields, this method combines those fields back into the original type, handling nested structures or composite fields.
Provided Methods§
Sourcefn from_bytes(data: &'a mut [u8]) -> Result<Self, Error>
fn from_bytes(data: &'a mut [u8]) -> Result<Self, Error>
Decodes the type from raw bytes.
Orchestrates the decoding process, calling get_structure to break down
the raw data, decoding each field, and then using from_decoded_fields to reassemble
the fields into the original type.
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.