bitbuffer rust example

Example: bitbuffer rust example

use bitbuffer::{BitBuffer, LittleEndian, BitStream, BitRead};

#[derive(BitRead)]
struct ComplexType {
    first: u8,
    #[size = 15]
    second: u16,
    third: bool,
}

fn main() {
    let bytes = vec![
        0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
        0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
    ];
    let buffer = BitBuffer::new(bytes, LittleEndian);
    let mut stream = BitStream::new(buffer);
    let value: u8 = stream.read_int(7)?;
    let complex: ComplexType = stream.read()?;
}

Tags:

Rust Example