pub struct Packet<'a> {
pub a: &'a [u8],
pub b: &'a [u8],
}Expand description
A borrowed view of a single packet from the ring buffer.
Because a packet’s payload may wrap across the end of the backing array, it is represented as
two contiguous slices. a is the first (or only) part of the payload; b is the second part
and is empty when the payload is contiguous.
Use Self::copy_into or Self::copy_part_into to copy the payload into a flat buffer.
Fields§
§a: &'a [u8]First (or only) slice of the packet payload.
b: &'a [u8]Second slice of the packet payload; empty when the payload is contiguous.
Implementations§
Source§impl<'a> Packet<'a>
impl<'a> Packet<'a>
Sourcepub fn copy_into(&self, buffer: &mut [u8])
pub fn copy_into(&self, buffer: &mut [u8])
Copies the full packet payload into buffer.
§Panics
Panics if buffer.len() != self.a.len() + self.b.len().
Sourcepub fn copy_part_into(&self, range: impl RangeBounds<usize>, buffer: &mut [u8])
pub fn copy_part_into(&self, range: impl RangeBounds<usize>, buffer: &mut [u8])
Copies the bytes in range of the packet payload into buffer.
The range is interpreted over the logical concatenation [a | b].
Any type implementing RangeBounds<usize> is accepted,
including 0..4, 2..=5, 1.., ..3, and ...
§Panics
Panics if buffer.len() does not equal the length implied by range, or if the resolved
range end exceeds self.a.len() + self.b.len().
Sourcepub fn extend_into<E: Extend<u8>>(&self, target: &mut E)
pub fn extend_into<E: Extend<u8>>(&self, target: &mut E)
Extends target with the full packet payload.
Appends the bytes from a followed by b to target. Works with any collection
that implements Extend<u8>, such as Vec<u8> or
heapless::Vec<u8, N>.