Macro nom::bytes [] [src]

macro_rules! bytes {
    ($i:expr, $submac:ident!( $($args:tt)* )) => { ... };
    ($i:expr, $f:expr) => { ... };
}

Counterpart to bits, bytes! transforms its bit stream input into a byte slice for the underlying parser, allowing byte-slice parsers to work on bit streams.

Signature: bytes!( parser ) => ( (&[u8], usize), &[u8] -> IResult<&[u8], T> ) -> IResult<(&[u8], usize), T>,

A partial byte remaining in the input will be ignored and the given parser will start parsing at the next full byte. ```

#[macro_use] extern crate nom;

use nom::rest;

fn main() {

named!( parse<(u8, u8, &[u8])>, bits!( tuple!( take_bits!(u8, 4), take_bits!(u8, 8), bytes!(rest) )));

let input = &[0xde, 0xad, 0xbe, 0xaf];

assert_eq!(parse( input ), Ok(( &[][..], (0xd, 0xea, &[0xbe, 0xaf][..]) )));

}