Trait packet::ParseBuffer

source ·
pub trait ParseBuffer: ShrinkBuffer + ContiguousBuffer {
    // Required method
    fn parse_with<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>(
        &'a mut self,
        args: ParseArgs
    ) -> Result<P, P::Error>;

    // Provided method
    fn parse<'a, P: ParsablePacket<&'a [u8], ()>>(
        &'a mut self
    ) -> Result<P, P::Error> { ... }
}
Expand description

A byte buffer used for parsing.

A ParseBuffer is a ContiguousBuffer that can shrink in size.

While a ParseBuffer allows the ranges covered by its prefix, body, and suffix to be modified, it only provides immutable access to their contents. For mutable access, see ParseBufferMut.

§Notable implementations

ParseBuffer is implemented for byte slices - &[u8] and &mut [u8]. These types do not implement GrowBuffer; once bytes are consumed from their bodies, those bytes are discarded and cannot be recovered.

Required Methods§

source

fn parse_with<'a, ParseArgs, P: ParsablePacket<&'a [u8], ParseArgs>>( &'a mut self, args: ParseArgs ) -> Result<P, P::Error>

Parses a packet with arguments.

parse_with is like parse, but it accepts arguments to pass to P::parse.

Provided Methods§

source

fn parse<'a, P: ParsablePacket<&'a [u8], ()>>( &'a mut self ) -> Result<P, P::Error>

Parses a packet from the body.

parse parses a packet from the body by invoking P::parse on a BufferView into this buffer. Any bytes consumed from the BufferView are also consumed from the body, and added to the prefix or suffix. After parse has returned, the buffer’s body will contain only those bytes which were not consumed by the call to P::parse.

See the BufferView and ParsablePacket documentation for more details.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a> ParseBuffer for &'a [u8]

source§

fn parse_with<'b, ParseArgs, P: ParsablePacket<&'b [u8], ParseArgs>>( &'b mut self, args: ParseArgs ) -> Result<P, P::Error>

source§

impl<'a> ParseBuffer for &'a mut [u8]

source§

fn parse_with<'b, ParseArgs, P: ParsablePacket<&'b [u8], ParseArgs>>( &'b mut self, args: ParseArgs ) -> Result<P, P::Error>

Implementors§

source§

impl ParseBuffer for EmptyBuf

source§

impl<A, B> ParseBuffer for Either<A, B>
where A: ParseBuffer, B: ParseBuffer,

source§

impl<B: AsRef<[u8]>> ParseBuffer for Buf<B>