Decodable

Trait Decodable 

Source
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§

Source

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.

Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl<'a> Decodable<'a> for bool

Source§

impl<'a> Decodable<'a> for f32

Source§

impl<'a> Decodable<'a> for u8

Source§

impl<'a> Decodable<'a> for u16

Source§

impl<'a> Decodable<'a> for u32

Source§

impl<'a> Decodable<'a> for u64

Implementors§

Source§

impl<'a> Decodable<'a> for U24

Source§

impl<'a> Decodable<'a> for B016M<'a>

Source§

impl<'a> Decodable<'a> for B0255<'a>

Source§

impl<'a> Decodable<'a> for B032<'a>

Source§

impl<'a> Decodable<'a> for B064K<'a>

Source§

impl<'a> Decodable<'a> for Signature<'a>

Source§

impl<'a> Decodable<'a> for U32AsRef<'a>

Source§

impl<'a> Decodable<'a> for U256<'a>

Source§

impl<'a, T: 'a + Sv2DataType<'a> + GetMarker + GetSize + Decodable<'a>> Decodable<'a> for Seq0255<'a, T>

Source§

impl<'a, T: 'a + Sv2DataType<'a> + GetMarker + GetSize + Decodable<'a>> Decodable<'a> for Seq064K<'a, T>

Source§

impl<'a, T: 'a + Sv2DataType<'a> + GetMarker + GetSize + Decodable<'a>> Decodable<'a> for Sv2Option<'a, T>