Macro nom::take_bits [−][src]
Consumes the specified number of bits and returns them as the specified type.
Signature:
take_bits!(type, count) => ( (&[T], usize), U, usize) -> IResult<(&[T], usize), U>
named!(bits_pair<(&[u8], usize), (u8, u8)>, pair!( take_bits!(4u8), take_bits!(4u8) ) ); named!( take_pair<(u8, u8)>, bits!( bits_pair ) ); let input = vec![0xAB, 0xCD, 0xEF]; let sl = &input[..]; assert_eq!(take_pair( sl ), Ok((&sl[1..], (0xA, 0xB))) ); assert_eq!(take_pair( &sl[1..] ), Ok((&sl[2..], (0xC, 0xD))) );