mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-04 00:54:07 +02:00
BitWriteStream::from_slice
This commit is contained in:
parent
bf27c72389
commit
5defbb274f
2 changed files with 50 additions and 0 deletions
|
|
@ -204,3 +204,24 @@ fn test_write_container() {
|
|||
assert_eq!(Rc::new(true), read.read().unwrap());
|
||||
assert_eq!(Arc::new(true), read.read().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_to_slice() {
|
||||
let mut data = [0; 32];
|
||||
{
|
||||
let mut stream = unsafe { BitWriteStream::from_slice(&mut data[..], LittleEndian) };
|
||||
|
||||
stream.write_bool(true).unwrap();
|
||||
stream.write_int(3253u16, 16).unwrap();
|
||||
stream.write_int(13253u64, 64).unwrap();
|
||||
}
|
||||
|
||||
let mut read = BitReadStream::from(BitReadBuffer::new(&data[..], LittleEndian));
|
||||
|
||||
assert_eq!(true, read.read_bool().unwrap());
|
||||
assert_eq!(3253u16, read.read::<u16>().unwrap());
|
||||
assert_eq!(13253u64, read.read::<u64>().unwrap());
|
||||
|
||||
// 0 padded
|
||||
assert_eq!(false, read.read_bool().unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue