Skip to main content

BitCodec

Trait BitCodec 

Source
pub trait BitCodec<const MSB: bool>: Sized {
    // Required methods
    fn decode(bytes: &[u8], at_bit: usize) -> Result<(Self, usize), ParseError>;
    fn encode<B: Buffer>(
        &self,
        out: &mut BitWriter<'_, B, MSB>,
    ) -> Result<(), Overflow>;
}
Expand description

A value whose width in bits is read from the wire.

The bit-level VarCodec. A #[var] field in a #[message(bits)] uses one.

Required Methods§

Source

fn decode(bytes: &[u8], at_bit: usize) -> Result<(Self, usize), ParseError>

Decode from bit at_bit of bytes. Returns the value and the bits consumed.

A successful decode must consume at least one bit.

§Errors

ParseError::Short if the bytes end inside the value, ParseError::Malformed if the value is too wide for Self.

Source

fn encode<B: Buffer>( &self, out: &mut BitWriter<'_, B, MSB>, ) -> Result<(), Overflow>

Write this value to the bit cursor.

§Errors

Overflow if the buffer has no room.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl BitCodec<true> for ExpGolomb

Available on crate feature num only.