Skip to content

Instantly share code, notes, and snippets.

@richo
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save richo/7c6ad8640ccda274a2b6 to your computer and use it in GitHub Desktop.

Select an option

Save richo/7c6ad8640ccda274a2b6 to your computer and use it in GitHub Desktop.
const BLOCK_ALIGN: usize = 4; // 32 bits
fn block_body<'a>(len: usize) -> Box<Fn(&'a [u8]) -> IResult<&'a [u8],&'a [u8]>> {
return Box::new(move |input:&'a [u8]| -> IResult<&'a [u8],&'a [u8]> {
if input.len() < len {
Incomplete(Needed::Size(len as u32))
} else {
let spill = (BLOCK_ALIGN - (len & 3 )) & 3;
let consumed: &'a [u8] = &input[len+spill..];
let parsed: &'a [u8] = &input[0..len];
Done(consumed, parsed)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment