[][src]Struct bitbuffer::BitReadBuffer

pub struct BitReadBuffer<E> where
    E: Endianness
{ /* fields omitted */ }

Buffer that allows reading integers of arbitrary bit length and non byte-aligned integers

Examples

use bitbuffer::{BitReadBuffer, LittleEndian, Result};

let bytes = vec![
    0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
    0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
];
let buffer = BitReadBuffer::new(bytes, LittleEndian);
// read 7 bits as u8, starting from bit 3
let result: u8 = buffer.read_int(3, 7)?;

Methods

impl<E> BitReadBuffer<E> where
    E: Endianness
[src]

pub fn new(bytes: Vec<u8>, _endianness: E) -> Self[src]

Create a new BitBuffer from a byte vector

Examples

use bitbuffer::{BitReadBuffer, LittleEndian};

let bytes = vec![
    0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
    0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
];
let buffer = BitReadBuffer::new(bytes, LittleEndian);

impl<E> BitReadBuffer<E> where
    E: Endianness
[src]

pub fn bit_len(&self) -> usize[src]

The available number of bits in the buffer

pub fn byte_len(&self) -> usize[src]

The available number of bytes in the buffer

pub fn read_bool(&self, position: usize) -> Result<bool>[src]

Read a single bit from the buffer as boolean

Errors

Examples

let result = buffer.read_bool(5)?;
assert_eq!(result, true);

pub fn read_int<T>(&self, position: usize, count: usize) -> Result<T> where
    T: PrimInt + BitOrAssign + IsSigned + UncheckedPrimitiveInt + BitXor
[src]

Read a sequence of bits from the buffer as integer

Errors

Examples

let result = buffer.read_int::<u16>(10, 9)?;
assert_eq!(result, 0b100_0110_10);

pub fn read_bytes(&self, position: usize, byte_count: usize) -> Result<Vec<u8>>[src]

Read a series of bytes from the buffer

Errors

Examples

assert_eq!(buffer.read_bytes(5, 3)?, &[0b0_1010_101, 0b0_1100_011, 0b1_1001_101]);
assert_eq!(buffer.read_bytes(0, 8)?, &[
    0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
    0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
]);

pub fn read_string(
    &self,
    position: usize,
    byte_len: Option<usize>
) -> Result<String>
[src]

Read a series of bytes from the buffer as string

You can either read a fixed number of bytes, or a dynamic length null-terminated string

Errors

Examples

// Fixed length string
assert_eq!(buffer.read_string(0, Some(13))?, "Hello world".to_owned());
// fixed length with null padding
assert_eq!(buffer.read_string(0, Some(16))?, "Hello world".to_owned());
// null terminated
assert_eq!(buffer.read_string(0, None)?, "Hello world".to_owned());

pub fn read_float<T>(&self, position: usize) -> Result<T> where
    T: Float + UncheckedPrimitiveFloat, 
[src]

Read a sequence of bits from the buffer as float

Errors

Examples

let result = buffer.read_float::<f32>(10)?;

Trait Implementations

impl<E: Endianness> Clone for BitReadBuffer<E>[src]

impl<E: Endianness> Debug for BitReadBuffer<E>[src]

impl<E: Endianness> From<BitReadBuffer<E>> for BitReadStream<E>[src]

impl<E: Endianness> From<Vec<u8>> for BitReadBuffer<E>[src]

Auto Trait Implementations

impl<E> !RefUnwindSafe for BitReadBuffer<E>

impl<E> !Send for BitReadBuffer<E>

impl<E> !Sync for BitReadBuffer<E>

impl<E> Unpin for BitReadBuffer<E> where
    E: Unpin

impl<E> UnwindSafe for BitReadBuffer<E> where
    E: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.