-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Hi,
I noticed that packing nested structs fails for partial Integer types when used in inner structs. Weirdly enough, this is only applicable for bits smaller than 5.
Following fields packed result in [0] being outputted.
use packed_struct::prelude::*;
#[derive(PackedStruct, PartialEq, Debug)]
#[packed_struct(bit_numbering = "msb0", endian = "msb")]
pub struct Outer {
#[packed_field(bits = "0")]
inner_field: Inner,
}
#[derive(PackedStruct, PartialEq, Debug)]
#[packed_struct(bit_numbering = "msb0", endian = "msb")]
pub struct Inner {
#[packed_field(bits = "0")]
val: Integer<u8, packed_bits::Bits<1>>,
}
fn main() {
let outer = Outer {
inner_field: Inner { val: 1.into() },
};
let packed = outer.pack().unwrap();
let unpacked = Outer::unpack_from_slice(&packed).unwrap();
println!("unpacked: {:#}", unpacked);
println!("datetime: {:#}", outer);
assert_eq!(outer, unpacked);
}Code example also available here: rustexplorer.com.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels