pub struct Packet { /* private fields */ }Expand description
A network packet with zero-copy buffer storage.
§Architecture
The Packet struct implements a “Lazy Zero-Copy View” model:
- Zero-Copy: The
datafield usesBytes, a reference-counted buffer. - Lazy: Fields are not parsed until accessed.
- Copy-on-Write: Mutation triggers cloning only when buffer is shared.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn from_bytes(data: impl Into<Bytes>) -> Self
pub fn from_bytes(data: impl Into<Bytes>) -> Self
Creates a packet from raw bytes without parsing.
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Creates a packet from a byte slice by copying the data.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new packet with pre-allocated capacity.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn is_dirty(&self) -> bool
pub fn layer_count(&self) -> usize
pub fn is_parsed(&self) -> bool
pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> Bytes
pub fn into_bytes(self) -> Bytes
pub fn layers(&self) -> &[LayerIndex]
pub fn get_layer(&self, kind: LayerKind) -> Option<&LayerIndex>
Sourcepub fn layer_bytes(&self, kind: LayerKind) -> Result<&[u8]>
pub fn layer_bytes(&self, kind: LayerKind) -> Result<&[u8]>
Returns the bytes for a specific layer.
Sourcepub fn ethernet(&self) -> Option<EthernetLayer>
pub fn ethernet(&self) -> Option<EthernetLayer>
Get the Ethernet layer view if present.
Sourcepub fn layer_enum(&self, idx: &LayerIndex) -> LayerEnum
pub fn layer_enum(&self, idx: &LayerIndex) -> LayerEnum
Get a LayerEnum for a given LayerIndex.
Sourcepub fn layer_enums(&self) -> Vec<LayerEnum>
pub fn layer_enums(&self) -> Vec<LayerEnum>
Get all layers as LayerEnum objects.
Sourcepub fn with_data_mut<F, R>(&mut self, f: F) -> R
pub fn with_data_mut<F, R>(&mut self, f: F) -> R
Applies a mutation function to the packet data.
pub fn set_byte(&mut self, offset: usize, value: u8)
pub fn set_bytes(&mut self, offset: usize, values: &[u8])
pub fn mark_dirty(&mut self)
pub fn mark_clean(&mut self)
pub fn add_layer(&mut self, index: LayerIndex)
pub fn set_data(&mut self, data: BytesMut)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnsafeUnpin for Packet
impl UnwindSafe for Packet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more