Crates.io | bitcursor |
lib.rs | bitcursor |
version | 1.0.0 |
source | src |
created_at | 2019-02-16 21:28:32.834803 |
updated_at | 2019-04-08 00:00:40.641493 |
description | Keeps 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 | |
id | 115242 |
size | 177,996 |
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
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