packet::serialize

Struct 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]>> FragmentedBuffer for Buf<B>

Source§

fn len(&self) -> usize

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

fn with_bytes<R, F>(&self, f: F) -> R
where F: for<'macro_a, 'macro_b> FnOnce(FragmentedBytes<'macro_a, 'macro_b>) -> R,

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

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

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: AsRef<[u8]> + AsMut<[u8]>> FragmentedBufferMut for Buf<B>

Source§

fn with_bytes_mut<R, F>(&mut self, f: F) -> R
where F: for<'macro_a, 'macro_b> FnOnce(FragmentedBytesMut<'macro_a, 'macro_b>) -> 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: RangeBounds<usize>>(&mut self, src: R, dest: 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<B: AsRef<[u8]>> GrowBuffer for Buf<B>

Source§

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

Gets a view into the parts of this GrowBuffer. Read more
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 Growf 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]> + AsMut<[u8]>> GrowBufferMut for Buf<B>

Source§

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

Gets a mutable view into the parts of this GrowBufferMut. Read more
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<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 for Buf<B>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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]>> ContiguousBuffer for Buf<B>

Source§

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

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<O, B> AsFragmentedByteSlice<B> for O
where 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 T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 B

Source§

type Buffer = B

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

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

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

fn serialize_new_buf<BB, A>( &self, outer: PacketConstraints, alloc: A, ) -> Result<BB, SerializeError<<A as BufferAlloc<BB>>::Error>>
where BB: ReusableBuffer, A: BufferAlloc<BB>,

Serializes the data into a new buffer without consuming self. Read more
Source§

fn serialize_vec( self, outer: PacketConstraints, ) -> 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( self, outer: PacketConstraints, ) -> 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: GrowBufferMut, 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>(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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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 B

Source§

impl<B> ContiguousBufferMut for B

Source§

impl<B> ReusableBuffer for B