mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
support reading unnamed structs
This commit is contained in:
parent
896dff8367
commit
e56f636905
2 changed files with 63 additions and 43 deletions
|
|
@ -265,6 +265,22 @@ fn test_read_rest_enum() {
|
|||
assert_eq!(TestEnumRest::Asd, stream.read().unwrap());
|
||||
}
|
||||
|
||||
#[derive(BitRead, PartialEq, Debug)]
|
||||
struct UnnamedSize(u8, #[size = 5] String, bool);
|
||||
|
||||
fn test_unnamed_struct() {
|
||||
let bytes = vec![
|
||||
12, 'h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let buffer = BitBuffer::new(bytes, LittleEndian);
|
||||
let mut stream = BitStream::from(buffer);
|
||||
|
||||
assert_eq!(
|
||||
UnnamedSize(12, "hello".to_string(), false),
|
||||
stream.read().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(BitRead, BitSize, PartialEq, Debug)]
|
||||
struct EmptyStruct;
|
||||
|
||||
|
|
@ -285,9 +301,13 @@ struct SizeStruct {
|
|||
bar: bool,
|
||||
}
|
||||
|
||||
#[derive(BitSize)]
|
||||
struct UnnamedSizeStruct(u8, #[size = 6] String, bool);
|
||||
|
||||
#[test]
|
||||
fn test_bit_size() {
|
||||
assert_eq!(bit_size_of::<SizeStruct>(), 8 + 8 * 6 + 1);
|
||||
assert_eq!(bit_size_of::<UnnamedSizeStruct>(), 8 + 8 * 6 + 1);
|
||||
}
|
||||
|
||||
#[derive(BitSizeSized)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue