bitcursor

Crates.iobitcursor
lib.rsbitcursor
version1.0.0
sourcesrc
created_at2019-02-16 21:28:32.834803
updated_at2019-04-08 00:00:40.641493
descriptionKeeps track of the bit position for an in wrapped memory buffer, and provides it with a read, seek implementation. Also applys a new trait called ReadBits which allows reading types that implement Unit from the cursor.
homepage
repository
max_upload_size
id115242
size177,996
(barrelll)

documentation

README

BitCursor

Crates.io docs MIT/Apache


Keeps track of the bit position for an in wrapped memory buffer, and provides it with a read, write, and seek implementation. Also provides some traits for reading any size primitive, unsigned or signed integer ReadBits && ForceReadBits

Examples

Read a u16 from a list of u8's, first from bit position 0 and then from bit position 2 + cursor position 1.

use {BitCursor, Readbits};

let data: [u8; 4] = [0b01101010, 0b11110001, 0b01110100, 0b10100001];
let mut bcurs = BitCursor::new(&data[..]);
let r = bcurs.read_bits::<u16>().unwrap();
assert_eq!(0b0110101011110001 as u16, r);
let _ = bcurs.seek(SeekFrom::Start(10));
let r = bcurs.read_bits::<u16>().unwrap();
assert_eq!(0b1100010111010010 as u16, r);

To see more examples see the tests module

Commit count: 0

cargo fmt