pub struct PacketBuffer<'a, H: 'a> { /* private fields */ }
Expand description
An UDP packet ring buffer.
Implementations§
Source§impl<'a, H> PacketBuffer<'a, H>
impl<'a, H> PacketBuffer<'a, H>
Sourcepub fn new<MS, PS>(
metadata_storage: MS,
payload_storage: PS,
) -> PacketBuffer<'a, H>
pub fn new<MS, PS>( metadata_storage: MS, payload_storage: PS, ) -> PacketBuffer<'a, H>
Create a new packet buffer with the provided metadata and payload storage.
Metadata storage limits the maximum number of packets in the buffer and payload storage limits the maximum total size of packets.
Sourcepub fn enqueue(&mut self, size: usize, header: H) -> Result<&mut [u8], Full>
pub fn enqueue(&mut self, size: usize, header: H) -> Result<&mut [u8], Full>
Enqueue a single packet with the given header into the buffer, and
return a reference to its payload, or return Err(Full)
if the buffer is full.
Sourcepub fn enqueue_with_infallible<'b, F>(
&'b mut self,
max_size: usize,
header: H,
f: F,
) -> Result<usize, Full>
pub fn enqueue_with_infallible<'b, F>( &'b mut self, max_size: usize, header: H, f: F, ) -> Result<usize, Full>
Call f
with a packet from the buffer large enough to fit max_size
bytes. The packet
is shrunk to the size returned from f
and enqueued into the buffer.
Sourcepub fn dequeue_with<'c, R, E, F>(
&'c mut self,
f: F,
) -> Result<Result<R, E>, Empty>
pub fn dequeue_with<'c, R, E, F>( &'c mut self, f: F, ) -> Result<Result<R, E>, Empty>
Call f
with a single packet from the buffer, and dequeue the packet if f
returns successfully, or return Err(EmptyError)
if the buffer is empty.
Sourcepub fn dequeue(&mut self) -> Result<(H, &mut [u8]), Empty>
pub fn dequeue(&mut self) -> Result<(H, &mut [u8]), Empty>
Dequeue a single packet from the buffer, and return a reference to its payload
as well as its header, or return Err(Error::Exhausted)
if the buffer is empty.
Sourcepub fn peek(&mut self) -> Result<(&H, &[u8]), Empty>
pub fn peek(&mut self) -> Result<(&H, &[u8]), Empty>
Peek at a single packet from the buffer without removing it, and return a reference to
its payload as well as its header, or return Err(Error:Exhausted)
if the buffer is empty.
This function otherwise behaves identically to dequeue.
Sourcepub fn packet_capacity(&self) -> usize
pub fn packet_capacity(&self) -> usize
Return the maximum number packets that can be stored.
Sourcepub fn payload_capacity(&self) -> usize
pub fn payload_capacity(&self) -> usize
Return the maximum number of bytes in the payload ring buffer.