mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
add write bytes and string and rename ReadError -> BitError
This commit is contained in:
parent
bce35aeb32
commit
e43b0b6bb2
7 changed files with 147 additions and 58 deletions
|
|
@ -113,3 +113,24 @@ fn test_write_float_be() {
|
|||
// 0 padded
|
||||
assert_eq!(false, read.read_bool().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_string_le() {
|
||||
let mut stream = BitWriteStream::new(LittleEndian);
|
||||
|
||||
stream.write_bool(true).unwrap();
|
||||
stream.write_string("null terminated", None).unwrap();
|
||||
stream.write_string("fixed length1", Some(16)).unwrap();
|
||||
stream.write_string("fixed length2", Some(16)).unwrap();
|
||||
|
||||
let data = stream.finish();
|
||||
let mut read = BitReadStream::from(BitReadBuffer::new(data, LittleEndian));
|
||||
|
||||
assert_eq!(true, read.read_bool().unwrap());
|
||||
assert_eq!("null terminated", read.read_string(None).unwrap());
|
||||
assert_eq!("fixed length1", read.read_string(Some(16)).unwrap());
|
||||
assert_eq!("fixed length2", read.read_string(Some(16)).unwrap());
|
||||
|
||||
// 0 padded
|
||||
assert_eq!(false, read.read_bool().unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue