Function nom::bits::bytes [−][src]
pub fn bytes<I, O, E1: ParseError<I> + ErrorConvert<E2>, E2: ParseError<(I, usize)>, P>(
parser: P
) -> impl Fn((I, usize)) -> IResult<(I, usize), O, E2> where
I: Slice<RangeFrom<usize>> + Clone,
P: Fn(I) -> IResult<I, O, E1>,
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.
A partial byte remaining in the input will be ignored and the given parser will start parsing at the next full byte.
ⓘ
use nom::bits::{bits, bytes, streaming::take_bits}; fn parse(input: &[u8]) -> IResult<&[u8], (u8, u8, &[u8])> { bits(tuple(( take_bits(4usize), take_bits(8usize), bytes(rest) )))(input) } let input = &[0xde, 0xad, 0xbe, 0xaf]; assert_eq!(parse( input ), Ok(( &[][..], (0xd, 0xea, &[0xbe, 0xaf][..]) )));