nom::take_bits! [] [src]

macro_rules! take_bits {
    ($i:expr, $t:ty, $count:expr) => { ... };
}

take_bits!(type, nb) => ( (&[T], usize), U, usize) -> IResult<(&[T], usize), U> generates a parser consuming the specified number of bytes

 named!( take_pair<(u8, u8)>, bits!( pair!( take_bits!( u8, 3 ), take_bits!(u8, 5) ) ) );

 let input = vec![0b10101010, 0b11110000, 0b00110011];
 let sl    = &input[..];

 assert_eq!(take_pair( sl ),       Done(&sl[1..], (5, 10)) );
 assert_eq!(take_pair( &sl[1..] ), Done(&sl[2..], (7, 16)) );