use winnow::{ModalResult, Parser as _, binary::le_u32, error::ContextError, token::take};
#[derive(Clone, Debug, PartialEq, PartialOrd, Hash)]
pub struct RiffChunk {
pub fourcc: [u8; 4],
pub len: u32,
}
pub fn chunk(input: &mut &[u8]) -> ModalResult<RiffChunk, ContextError> {
let fourcc: [u8; 4] = {
let slice: &[u8] = take(4_usize).parse_next(input)?;
let Ok(fourcc) = slice.try_into() else {
unreachable!(
"fourcc slice is known to be `n` elements long. please report this - it's a bug!"
);
};
fourcc
};
let len: u32 = le_u32.parse_next(input)?;
Ok(RiffChunk { fourcc, len })
}