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
impl Packet
Sourcepub fn new_boxed() -> Box<Self>
pub fn new_boxed() -> Box<Self>
Create a new packet instance on the heap and returns the box containing it.
Sourcepub fn raw_mut(&mut self) -> &mut RawPacket
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.
Sourcepub fn content_max_len(&self) -> usize
pub fn content_max_len(&self) -> usize
Return the maximum content length.
Sourcepub fn content_len(&self) -> usize
pub fn content_len(&self) -> usize
Return the length of the content.
Sourcepub fn content_available_len(&self) -> usize
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.
Sourcepub fn content(&self) -> &[u8] ⓘ
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.
Sourcepub fn content_mut(&mut self) -> &mut [u8] ⓘ
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.
Sourcepub fn grow(&mut self, len: usize) -> &mut [u8] ⓘ
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.
Sourcepub fn grow_write(&mut self, len: usize) -> impl Write + '_
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.
Return the length of the footer. It should not exceed PACKET_MAX_FOOTER_LEN.
Return the available length remaining in the footer.
Sourcepub fn first_request_offset(&self) -> Option<usize>
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.
Sourcepub fn set_first_request_offset(&mut self, offset: usize)
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.
Sourcepub fn clear_first_request_offset(&mut self)
pub fn clear_first_request_offset(&mut self)
Clear the first request offset.
Sourcepub fn write_config(&mut self, config: &mut PacketConfig)
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.
Sourcepub fn read_config(
&mut self,
len: usize,
config: &mut PacketConfig,
) -> Result<(), PacketConfigError>
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.