Function bytes

Source
pub fn bytes<Input, Output, ByteError, BitError, ParseNext>(
    parser: ParseNext,
) -> impl Parser<(Input, usize), Output, BitError>
where ByteError: ParserError<Input> + ErrorConvert<BitError>, BitError: ParserError<(Input, usize)>, Input: Stream<Token = u8> + Clone, ParseNext: Parser<Input, Output, ByteError>,
Expand description

Convert a bits stream back into a byte stream

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

§Examples

use winnow::binary::bits::{bits, bytes, take};

type Stream<'i> = &'i Bytes;

fn stream(b: &[u8]) -> Stream<'_> {
    Bytes::new(b)
}

fn parse<'i>(input: &mut Stream<'i>) -> ModalResult<(u8, u8, &'i [u8])> {
  bits::<_, _, ErrMode<ContextError>, _, _>((
    take(4usize),
    take(8usize),
    bytes::<_, _, ErrMode<ContextError>, _, _>(rest)
  )).parse_next(input)
}

let input = stream(&[0x12, 0x34, 0xff, 0xff]);

assert_eq!(parse.parse_peek(input), Ok(( stream(&[]), (0x01, 0x23, &[0xff, 0xff][..]) )));