RawPacket

Struct RawPacket 

Source
pub struct RawPacket { /* private fields */ }
Expand description

Raw packet layout with only data and length. This structure provides functions for growing and shrinking data, retrieving and modifying its length. Other states such are footer offset or first request offset are not saved in this structure, because this structure is intended to be used as backend of the Packet structure which contains such state.

The internal data is split in multiple slices that are accessible through the API:

  • Raw data, it contains the full internal data with max data length, this should be used for receiving datagram from the network;

  • Data, it contains all the data up to the packet’s length;

  • Body, it contains all the data starting with the packet’s flags up to the packet’s length.

Implementations§

Source§

impl RawPacket

Source

pub fn new() -> Self

Source

pub fn raw_data(&self) -> &[u8]

Get a slice to the full raw data, this means that this isn’t constrained by the length of the packet.

Source

pub fn raw_data_mut(&mut self) -> &mut [u8]

Get a mutable slice to the full raw data, this means that this isn’t constrained by the length of the packet.

This mutable slice can be used to receive data from an UDP datagram.

Source

pub fn data_max_len(&self) -> usize

Return the maximum size of a packet.

Source

pub fn data_len(&self) -> usize

Return the length of this packet.

Source

pub fn data_available_len(&self) -> usize

Return the available length in this packet.

Source

pub fn set_data_len(&mut self, len: usize)

Set the length of this packet. The function panics if the length is not at least PACKET_MIN_LEN or at most PACKET_MAX_LEN.

Source

pub fn data(&self) -> &[u8]

Get a slice to the data, with the packet’s length.

This slice can be used to send data as an UDP datagram for exemple.

Source

pub fn data_mut(&mut self) -> &mut [u8]

Get a mutable slice to the data, with the packet’s length.

Source

pub fn max_body_len(&self) -> usize

Return the maximum size of the body of a packet.

Source

pub fn body_len(&self) -> usize

Return the length of this packet.

Source

pub fn body(&self) -> &[u8]

Get a slice to the data from after the prefix to the end.

Source

pub fn body_mut(&mut self) -> &mut [u8]

Get a mutable slice to the data from after the prefix to the end.

Source

pub fn reset(&mut self)

Reset this packet’s length, flags and prefix.

Source

pub fn grow(&mut self, len: usize) -> &mut [u8]

Grow the packet’s data by a given amount of bytes, and return a mutable slice to the newly allocated data.

This function panics if the available length is smaller than requested length.

Source

pub fn grow_write(&mut self, len: usize) -> impl Write + Seek + '_

Grow the packet’s data by a given amount of bytes, and return a writer to the given data. This writer can be used to write new data to the newly allocated data.

This function panics if the available length is smaller than requested length.

Source

pub fn shrink(&mut self, len: usize) -> &[u8]

Shrink the packet’s data by a given amount of bytes, and return a slice to the deallocated data. The slice is not mutable because returned data is no longer contained in packet’s data.

The discarded data is left untouched, which mean that you can rollback to the previous length to recover the data.

This function panics if the length after shrink is lower than prefix (4 bytes) + flags (2) bytes.

Source

pub fn shrink_read(&mut self, len: usize) -> impl Read + '_

Shrink the packet’s data by a given amount of bytes, and return a reader to the freed data.

This function panics if the length after shrink is lower than prefix (4 bytes) + flags (2) bytes.

Source

pub fn read_prefix(&self) -> u32

Read the prefix of this packet.

Source

pub fn write_prefix(&mut self, prefix: u32)

Write the prefix of this packet.

Source

pub fn read_flags(&self) -> u16

Read the flags of this packet.

Source

pub fn write_flags(&mut self, flags: u16)

Write the flags of this packet.

Trait Implementations§

Source§

impl Clone for RawPacket

Source§

fn clone(&self) -> RawPacket

Returns a duplicate 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 Debug for RawPacket

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V