Struct packet::serialize::Buf

source ·
pub struct Buf<B> { /* private fields */ }
Expand description

A byte slice wrapper providing buffer functionality.

A Buf wraps a byte slice (a type which implements AsRef<[u8]> or AsMut<[u8]>) and implements various buffer traits by keeping track of prefix, body, and suffix offsets within the byte slice.

Implementations§

source§

impl Buf<Vec<u8>>

source

pub fn into_inner(self) -> Vec<u8>

Extracts the contained data trimmed to the buffer’s range.

source§

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

source

pub fn new<R: RangeBounds<usize>>(buf: B, body: R) -> Buf<B>

Constructs a new Buf.

new constructs a new Buf from a buffer and a body range. The bytes within the range will be the body, the bytes before the range will be the prefix, and the bytes after the range will be the suffix.

Panics

Panics if range is out of bounds of buf, or if it is nonsensical (the end precedes the start).

source

pub fn buffer_view(&mut self) -> BufView<'_>

Constructs a BufView which will be a BufferView into this Buf.

source§

impl<B: AsRef<[u8]> + AsMut<[u8]>> Buf<B>

source

pub fn buffer_view_mut(&mut self) -> BufViewMut<'_>

Constructs a BufViewMut which will be a BufferViewMut into this Buf.

Trait Implementations§

source§

impl<B: AsMut<[u8]>> AsMut<[u8]> for Buf<B>

source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

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

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

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

source§

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

Like ParseBuffer::parse_with but additionally provides an un-structured view into the parsed data on successful parsing.
source§

impl<B: Clone> Clone for Buf<B>

source§

fn clone(&self) -> Buf<B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<B: Debug> Debug for Buf<B>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

source§

fn capacity(&self) -> usize

The capacity of the buffer. Read more
source§

fn prefix_len(&self) -> usize

The length of the prefix.
source§

fn suffix_len(&self) -> usize

The length of the suffix.
source§

fn grow_front(&mut self, n: usize)

Grows the front of the body towards the beginning of the buffer. Read more
source§

fn grow_back(&mut self, n: usize)

Grows the back of the body towards the end of the buffer. Read more
source§

fn reset(&mut self)

Resets the body to be equal to the entire buffer. Read more
source§

fn undo_parse(&mut self, meta: ParseMetadata)

Undoes the effects of a previous parse in preparation for serialization. Read more
source§

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

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. Read more
source§

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

Parses a packet from the body. Read more
source§

impl<B: AsRef<[u8]> + AsMut<[u8]>> ParseBufferMut for Buf<B>

source§

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

Parses a mutable packet with arguments. Read more
source§

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

Parses a mutable packet from the body. Read more
source§

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

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

fn shrink<R: RangeBounds<usize>>(&mut self, range: R)

Shrinks the body. Read more
source§

fn shrink_front(&mut self, n: usize)

Shrinks the front of the body towards the end of the buffer. Read more
source§

fn shrink_back(&mut self, n: usize)

Shrinks the back of the body towards the beginning of the buffer. Read more
source§

fn shrink_front_to(&mut self, len: usize)

Shrinks the buffer to be no larger than len bytes, consuming from the front. Read more
source§

fn shrink_back_to(&mut self, len: usize)

Shrinks the buffer to be no larger than len bytes, consuming from the back. Read more
source§

impl<B: AsRef<[u8]> + AsMut<[u8]>> TargetBuffer for Buf<B>

source§

fn with_parts<O, F>(&mut self, f: F) -> Owhere F: for<'a, 'b> FnOnce(&'a mut [u8], FragmentedBytesMut<'a, 'b>, &'a mut [u8]) -> O,

Gets a view into the parts of this TargetBuffer. Read more
source§

fn serialize<B: PacketBuilder>(&mut self, c: PacketConstraints, builder: B)

Serializes a packet in the buffer. Read more
source§

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

source§

impl<B: AsRef<[u8]> + AsMut<[u8]>> ContiguousBufferMutImpl for Buf<B>

source§

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

Auto Trait Implementations§

§

impl<B> RefUnwindSafe for Buf<B>where B: RefUnwindSafe,

§

impl<B> Send for Buf<B>where B: Send,

§

impl<B> Sync for Buf<B>where B: Sync,

§

impl<B> Unpin for Buf<B>where B: Unpin,

§

impl<B> UnwindSafe for Buf<B>where B: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<O, B> AsFragmentedByteSlice<B> for Owhere B: Fragment, O: AsMut<[B]>,

source§

fn as_fragmented_byte_slice(&mut self) -> FragmentedByteSlice<'_, B>

Generates a FragmentedByteSlice view of self.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<B> FragmentedBuffer for Bwhere B: ContiguousBufferImpl,

source§

fn len(&self) -> usize

Gets the total length, in bytes, of this FragmentedBuffer.
source§

fn with_bytes<R, F>(&self, f: F) -> Rwhere F: for<'a, 'b> FnOnce(FragmentedByteSlice<'a, &'b [u8]>) -> R,

Invokes a callback on a view into this buffer’s contents as FragmentedBytes.
source§

fn to_flattened_vec(&self) -> Vec<u8, Global>

Returns a flattened version of this buffer, copying its contents into a Vec.
source§

fn is_empty(&self) -> bool

Returns true if this FragmentedBuffer is empty.
source§

impl<B> FragmentedBufferMut for Bwhere B: ContiguousBufferMutImpl + ContiguousBufferImpl,

source§

fn with_bytes_mut<R, F>(&mut self, f: F) -> Rwhere F: for<'a, 'b> FnOnce(FragmentedByteSlice<'a, &'b mut [u8]>) -> R,

Invokes a callback on a mutable view into this buffer’s contents as FragmentedBytesMut.
source§

fn zero_range<R>(&mut self, range: R)where R: RangeBounds<usize>,

Sets all bytes in range to zero. Read more
source§

fn copy_within<R>(&mut self, src: R, dest: usize)where R: RangeBounds<usize>,

Copies elements from one part of the FragmentedBufferMut to another part of itself. Read more
source§

fn copy_from<B: FragmentedBuffer>(&mut self, other: &B)

Copies all the bytes from another FragmentedBuffer other into self. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<B> GrowBufferMut for Bwhere B: GrowBuffer + FragmentedBufferMut,

source§

fn grow_front_zero(&mut self, n: usize)

Extends the front of the body towards the beginning of the buffer, zeroing the new bytes. Read more
source§

fn grow_back_zero(&mut self, n: usize)

Extends the back of the body towards the end of the buffer, zeroing the new bytes. Read more
source§

fn reset_zero(&mut self)

Resets the body to be equal to the entire buffer, zeroing the new bytes. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<B> Serializer for Bwhere B: GrowBuffer + ShrinkBuffer,

§

type Buffer = B

The type of buffers returned from serialization methods on this trait.
source§

fn serialize<BB, PB, P>( self, outer: PB, provider: P ) -> Result<BB, (SerializeError<<P as BufferProvider<<B as Serializer>::Buffer, BB>>::Error>, B)>where BB: TargetBuffer, PB: NestedPacketBuilder, P: BufferProvider<<B as Serializer>::Buffer, BB>,

Serializes this Serializer, producing a buffer. Read more
source§

fn serialize_vec<PB: NestedPacketBuilder>( self, outer: PB ) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where Self::Buffer: ReusableBuffer,

Serializes this Serializer, allocating a Buf<Vec<u8>> if the contained buffer isn’t large enough. Read more
source§

fn serialize_no_alloc<PB: NestedPacketBuilder>( self, outer: PB ) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where Self::Buffer: ReusableBuffer,

Serializes this Serializer, failing if the existing buffer is not large enough. Read more
source§

fn serialize_outer<B: TargetBuffer, P: BufferProvider<Self::Buffer, B>>( self, provider: P ) -> Result<B, (SerializeError<P::Error>, Self)>

Serializes this Serializer as the outermost packet. Read more
source§

fn serialize_vec_outer( self ) -> Result<Either<Self::Buffer, Buf<Vec<u8>>>, (SerializeError<Never>, Self)>where Self::Buffer: ReusableBuffer,

Serializes this Serializer as the outermost packet, allocating a Buf<Vec<u8>> if the contained buffer isn’t large enough. Read more
source§

fn serialize_no_alloc_outer( self ) -> Result<Self::Buffer, (SerializeError<BufferTooShortError>, Self)>where Self::Buffer: ReusableBuffer,

Serializes this Serializer as the outermost packet, failing if the existing buffer is not large enough. Read more
source§

fn encapsulate<B: NestedPacketBuilder>(self, outer: B) -> Nested<Self, B>

Encapsulates this Serializer in another packet, producing a new Serializer. Read more
source§

fn with_size_limit( self, limit: usize ) -> Nested<Self, LimitedSizePacketBuilder<()>>

Creates a new Serializer which will enforce a size limit. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<B> BufferMut for Bwhere B: TargetBuffer + ParseBufferMut + Buffer,

source§

impl<B> ContiguousBuffer for Bwhere B: ContiguousBufferImpl,

source§

impl<B> ContiguousBufferMut for Bwhere B: ContiguousBufferMutImpl,

source§

impl<B> ReusableBuffer for Bwhere B: TargetBuffer + ShrinkBuffer,