1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-04 00:54:07 +02:00

allow for simple math in size reference

This commit is contained in:
Robin Appelman 2019-02-28 22:19:04 +01:00
commit 92b5763aea
2 changed files with 44 additions and 11 deletions

View file

@ -178,3 +178,37 @@ fn test_read_unnamed_field_enum_sized() {
);
assert_eq!(8, stream.pos());
}
#[derive(BitRead, PartialEq, Debug)]
struct TestStruct2 {
size: u8,
#[size = "size * 2"]
str: String,
}
#[test]
fn test_read_struct2() {
let bytes = vec![
0b0000_0101,
'h' as u8,
'e' as u8,
'l' as u8,
'l' as u8,
'o' as u8,
' ' as u8,
'w' as u8,
'o' as u8,
'r' as u8,
'l' as u8,
'e' as u8,
];
let buffer = BitBuffer::new(bytes, BigEndian);
let mut stream = BitStream::from(buffer);
assert_eq!(
TestStruct2 {
size: 5,
str: "hello worl".to_owned(),
},
stream.read().unwrap()
);
}