Packet

Struct Packet 

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

Represent a RawPacket with additional state. The additional state keeps track of different offsets in the packet’s raw data. Like footer and first request element offsets. This structure also provides functions for synchronizing data from the state and vice-versa.

This structure only expose a single slice of data which contain the content data, starting after the flags and ending before the footer. To access more low-level slices you can should use the raw packet.

Implementations§

Source§

impl Packet

Source

pub fn new() -> Self

Create a new packet instance.

Source

pub fn new_boxed() -> Box<Self>

Create a new packet instance on the heap and returns the box containing it.

Source

pub fn raw(&self) -> &RawPacket

Return a shared reference to the internal raw packet.

Source

pub fn raw_mut(&mut self) -> &mut RawPacket

Return a mutable reference to the internal raw packet.

You should be really careful when manipulating the internal data and always prefer using methods of this structure over manipulating the raw data from external modules.

Source

pub fn content_max_len(&self) -> usize

Return the maximum content length.

Source

pub fn content_len(&self) -> usize

Return the length of the content.

Source

pub fn content_available_len(&self) -> usize

Return the available body length for writing elements. The rest of the length might be used for the footer.

Source

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

Return a slice to the content of this packet. The content starts after the flags and finish before the footer.

Source

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

Return a mutable slice to the content of this packet. The content starts after the flags and finish before the footer.

Source

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

Grow this packet’s content by the given size. You must ensure that there is enough space for such size, you can obtain remaining length using the content_available_len function.

Note that because growing the body might overwrite the footer, this function reset the footer to zero length. Calling footer_len() after this function returns 0.

Source

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

Grow this packet’s content by the given size and return a writer to the location to write. See grow function for more information.

Source

pub fn footer_len(&self) -> usize

Return the length of the footer. It should not exceed PACKET_MAX_FOOTER_LEN.

Source

pub fn footer_available_len(&self) -> usize

Return the available length remaining in the footer.

Source

pub fn first_request_offset(&self) -> Option<usize>

Return the offset of the next request element in this packet. Because this offset cannot be equal to 0 or 1 (which points to packet’s flags), such values are sentinels that fill returns None.

Source

pub fn set_first_request_offset(&mut self, offset: usize)

Set the first offset of the next request element in this packet. Refer to first_request_offset function for limitations.

Source

pub fn clear_first_request_offset(&mut self)

Clear the first request offset.

Source

pub fn write_config(&mut self, config: &mut PacketConfig)

Write the given configuration to this packet’s flags and footer. This function takes a configuration that will be applied to the packet, the configuration must be mutable because the function will try to put the maximum number of acks in the footer, the remaining acks will be left over in the config.

Source

pub fn read_config( &mut self, len: usize, config: &mut PacketConfig, ) -> Result<(), PacketConfigError>

Read the configuration from this packet’s flags and footer.

Note that the given length must account for the prefix.

If this function returns an error, the integrity of the configuration is not guaranteed.

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

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 Packet

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Packet

§

impl RefUnwindSafe for Packet

§

impl Send for Packet

§

impl Sync for Packet

§

impl Unpin for Packet

§

impl UnwindSafe for Packet

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