packet

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so 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>