-
-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
DekuSize is very useful to me, but I noticed an issue: the bytes occupied by the magic attribute are not being counted in SIZE_BYTES.
In some scenarios, I need to calculate the total number of bytes written to a file, which means the bytes from the magic attribute are always missing.
Here’s an example:
use deku::prelude::*;
#[derive(DekuSize)]
#[deku(magic = b"DEMO")]
struct Demo {
foo: u32,
bar: u32,
}
impl Demo {
const SIZE: usize = Self::SIZE_BYTES.unwrap();
}
fn main() {
let size = Demo::SIZE;
assert_eq!(size, 12);
}Running via cargo run:
thread 'main' panicked at src/main.rs:16:5:
assertion `left == right` failed
left: 8
right: 12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expected behavior:
SIZE_BYTES should include the 4 bytes from the magic attribute, so the total should be 12 instead of 8.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels