in mp4parse/src/tests.rs [29:71]
fn make_box<F>(size: BoxSize, name: &[u8; 4], func: F) -> Cursor<Vec<u8>>
where
F: Fn(Section) -> Section,
{
let mut section = Section::new();
let box_size = Label::new();
section = match size {
BoxSize::Short(size) | BoxSize::UncheckedShort(size) => section.B32(size),
BoxSize::Long(_) | BoxSize::UncheckedLong(_) => section.B32(1),
BoxSize::Auto => section.B32(&box_size),
};
section = section.append_bytes(name);
section = match size {
// The spec allows the 32-bit size to be 0 to indicate unknown
// length streams. It's not clear if this is valid when using a
// 64-bit size, so prohibit it for now.
BoxSize::Long(size) => {
assert!(size > 0);
section.B64(size)
}
BoxSize::UncheckedLong(size) => section.B64(size),
_ => section,
};
section = func(section);
match size {
BoxSize::Short(size) => {
if size > 0 {
assert_eq!(u64::from(size), section.size())
}
}
BoxSize::Long(size) => assert_eq!(size, section.size()),
BoxSize::Auto => {
assert!(
section.size() <= u64::from(u32::MAX),
"Tried to use a long box with BoxSize::Auto"
);
box_size.set_const(section.size());
}
// Skip checking BoxSize::Unchecked* cases.
_ => (),
}
Cursor::new(section.get_contents().unwrap())
}