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
impl RawPacket
pub fn new() -> Self
Sourcepub fn raw_data(&self) -> &[u8] ⓘ
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.
Sourcepub fn raw_data_mut(&mut self) -> &mut [u8] ⓘ
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.
Sourcepub fn data_max_len(&self) -> usize
pub fn data_max_len(&self) -> usize
Return the maximum size of a packet.
Sourcepub fn data_available_len(&self) -> usize
pub fn data_available_len(&self) -> usize
Return the available length in this packet.
Sourcepub fn set_data_len(&mut self, len: usize)
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.
Sourcepub fn data(&self) -> &[u8] ⓘ
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.
Sourcepub fn data_mut(&mut self) -> &mut [u8] ⓘ
pub fn data_mut(&mut self) -> &mut [u8] ⓘ
Get a mutable slice to the data, with the packet’s length.
Sourcepub fn max_body_len(&self) -> usize
pub fn max_body_len(&self) -> usize
Return the maximum size of the body of a packet.
Sourcepub fn body_mut(&mut self) -> &mut [u8] ⓘ
pub fn body_mut(&mut self) -> &mut [u8] ⓘ
Get a mutable slice to the data from after the prefix to the end.
Sourcepub fn grow(&mut self, len: usize) -> &mut [u8] ⓘ
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.
Sourcepub fn grow_write(&mut self, len: usize) -> impl Write + Seek + '_
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.
Sourcepub fn shrink(&mut self, len: usize) -> &[u8] ⓘ
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.
Sourcepub fn shrink_read(&mut self, len: usize) -> impl Read + '_
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.
Sourcepub fn read_prefix(&self) -> u32
pub fn read_prefix(&self) -> u32
Read the prefix of this packet.
Sourcepub fn write_prefix(&mut self, prefix: u32)
pub fn write_prefix(&mut self, prefix: u32)
Write the prefix of this packet.
Sourcepub fn read_flags(&self) -> u16
pub fn read_flags(&self) -> u16
Read the flags of this packet.
Sourcepub fn write_flags(&mut self, flags: u16)
pub fn write_flags(&mut self, flags: u16)
Write the flags of this packet.