use binrw::BinRead;
use std::io::Cursor;
#[derive(BinRead, Debug, Clone, PartialEq, Eq)]
#[br(big)]
pub struct ApplyFreeSpace {
#[br(map = |x: u64| x as i64)]
pub unknown_a: i64,
#[br(map = |x: u64| x as i64)]
pub unknown_b: i64,
}
pub(crate) fn parse(body: &[u8]) -> crate::Result<ApplyFreeSpace> {
Ok(ApplyFreeSpace::read_be(&mut Cursor::new(body))?)
}
#[cfg(test)]
mod tests {
use super::parse;
#[test]
fn parses_apply_free_space() {
let mut body = Vec::new();
body.extend_from_slice(&0x8000_0000_0000_0000_u64.to_be_bytes()); body.extend_from_slice(&1u64.to_be_bytes());
let cmd = parse(&body).unwrap();
assert_eq!(cmd.unknown_a, i64::MIN);
assert_eq!(cmd.unknown_b, 1);
}
#[test]
fn rejects_truncated_body() {
assert!(parse(&[0u8; 8]).is_err());
}
}