Skip to content

Rust bitpack library. support `no_std` environment.

License

Notifications You must be signed in to change notification settings

quininer/bitpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bitpack

let mut buff = [0; 2];

// write
{
    let mut bitpack = BitPack::<&mut [u8]>::new(&mut buff);
    bitpack.write(10, 4).unwrap();
    bitpack.write(1021, 10).unwrap();
    bitpack.write(3, 2).unwrap();
}

assert_eq!(buff, [218, 255]);

// read
{
    let mut bitpack = BitPack::<&[u8]>::new(&buff);
    assert_eq!(bitpack.read(4).unwrap(), 10);
    assert_eq!(bitpack.read(10).unwrap(), 1021);
    assert_eq!(bitpack.read(2).unwrap(), 3);
}

and, use_std

let mut bitpack_vec = BitPack::<Vec<u8>>::with_capacity(2);
bitpack_vec.write(10, 4).unwrap();
bitpack_vec.write(1021, 10).unwrap();
bitpack_vec.write(3, 2).unwrap();

assert_eq!(bitpack_vec.as_slice(), [218, 255]);

let mut bitpack = BitPack::<&[u8]>::new(bitpack_vec.as_slice());
assert_eq!(bitpack.read(4).unwrap(), 10);
assert_eq!(bitpack.read(10).unwrap(), 1021);
assert_eq!(bitpack.read(2).unwrap(), 3);

About

Rust bitpack library. support `no_std` environment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages