BitCodec

Trait BitCodec 

Source
pub trait BitCodec:
    BitDecode
    + BitEncode
    + Sealed {
    // Provided methods
    fn decode_bytes<E>(bytes: &[u8], byte_order: E) -> Result<(Self, u64)>
       where E: Endianness { ... }
    fn decode_all_bytes<E>(bytes: &[u8], byte_order: E) -> Result<Self>
       where E: Endianness { ... }
    fn encode_bytes<E>(&self, byte_order: E) -> Result<Vec<u8>>
       where E: Endianness { ... }
    fn encode_bytes_buf<E>(&self, byte_order: E, buf: &mut [u8]) -> Result<u64>
       where E: Endianness { ... }
}
Expand description

A trait with helper functions for simple codecs.

Provided Methods§

Source

fn decode_bytes<E>(bytes: &[u8], byte_order: E) -> Result<(Self, u64)>
where E: Endianness,

Parses a new value from its raw byte representation.

Returns a tuple of the parsed value and the number of bits read.

Source

fn decode_all_bytes<E>(bytes: &[u8], byte_order: E) -> Result<Self>
where E: Endianness,

Parses a new value from its raw byte representation, consuming entire buffer.

Source

fn encode_bytes<E>(&self, byte_order: E) -> Result<Vec<u8>>
where E: Endianness,

Available on crate feature alloc only.

Gets the raw bytes of this type.

Source

fn encode_bytes_buf<E>(&self, byte_order: E, buf: &mut [u8]) -> Result<u64>
where E: Endianness,

Fills the buffer with the raw bytes of this type.

Returns the number of bytes written.

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.

Implementors§

Source§

impl<T> BitCodec for T
where T: BitDecode + BitEncode + Sealed,