use binrw::BinRead;
use super::util::read_null_trimmed_utf8;
#[derive(BinRead, Debug, Clone, PartialEq, Eq)]
#[br(big)]
pub struct AddDirectory {
#[br(parse_with = read_null_trimmed_utf8)]
pub name: String,
}
pub(crate) fn parse(body: &[u8]) -> crate::Result<AddDirectory> {
super::util::parse_be(body)
}
#[cfg(test)]
mod tests {
use super::parse;
#[test]
fn parses_add_directory() {
let mut body = Vec::new();
body.extend_from_slice(&5u32.to_be_bytes());
body.extend_from_slice(b"sqex\0");
assert_eq!(parse(&body).unwrap().name, "sqex");
}
#[test]
fn null_padding_trimmed() {
let mut body = Vec::new();
body.extend_from_slice(&8u32.to_be_bytes());
body.extend_from_slice(b"ex\0\0\0\0\0\0");
assert_eq!(parse(&body).unwrap().name, "ex");
}
}