Trait FixedWidthEncoding

Source
pub trait FixedWidthEncoding {
    type Decode;

    // Required methods
    fn fw_encoded_size(&self) -> Result<usize, EncodingError>;
    fn fw_encode<'a>(
        &self,
        buffer: &'a mut [u8],
    ) -> Result<&'a mut [u8], EncodingError>;
    fn fw_decode(buffer: &[u8]) -> Result<(Self::Decode, &[u8]), EncodingError>
       where Self: Sized;

    // Provided method
    fn as_fixed_width(&self) -> FixedWidthUint<'_, Self> { ... }
}
Expand description

Implents functionality needed to encode unisegned integrer in a fixed width way with CompactEncoding

Required Associated Types§

Source

type Decode

The type we decode to

Required Methods§

Source

fn fw_encoded_size(&self) -> Result<usize, EncodingError>

The size in bytes required to encode self.

Source

fn fw_encode<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], EncodingError>

Encode self into buffer returning the remainder of buffer.

Source

fn fw_decode(buffer: &[u8]) -> Result<(Self::Decode, &[u8]), EncodingError>
where Self: Sized,

Decode a value from the given buffer of the type specified by the Decode type parameter (which defaults to Self). Returns the decoded value and remaining undecoded bytes.

Provided Methods§

Source

fn as_fixed_width(&self) -> FixedWidthUint<'_, Self>

Get a uint in a form that encodes to a fixed width

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 FixedWidthEncoding for u32

Source§

type Decode = u32

Source§

fn fw_encoded_size(&self) -> Result<usize, EncodingError>

Source§

fn fw_encode<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], EncodingError>

Source§

fn fw_decode(buffer: &[u8]) -> Result<(Self::Decode, &[u8]), EncodingError>
where Self: Sized,

Source§

impl FixedWidthEncoding for u64

Source§

type Decode = u64

Source§

fn fw_encoded_size(&self) -> Result<usize, EncodingError>

Source§

fn fw_encode<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], EncodingError>

Source§

fn fw_decode(buffer: &[u8]) -> Result<(Self::Decode, &[u8]), EncodingError>
where Self: Sized,

Implementors§