pub struct Packet { /* private fields */ }Expand description
Ordered stack of packet layers.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn from_layer<L>(layer: L) -> Selfwhere
L: Layer,
pub fn from_layer<L>(layer: L) -> Selfwhere
L: Layer,
Create a packet containing one layer.
Sourcepub fn push<L>(self, layer: L) -> Selfwhere
L: Layer,
pub fn push<L>(self, layer: L) -> Selfwhere
L: Layer,
Append a concrete layer and return the packet for builder chaining.
Sourcepub fn push_box(self, layer: Box<dyn Layer>) -> Self
pub fn push_box(self, layer: Box<dyn Layer>) -> Self
Append a boxed layer and return the packet for builder chaining.
Sourcepub fn push_mut<L>(&mut self, layer: L) -> &mut Selfwhere
L: Layer,
pub fn push_mut<L>(&mut self, layer: L) -> &mut Selfwhere
L: Layer,
Mutably append a concrete layer.
Sourcepub fn push_box_mut(&mut self, layer: Box<dyn Layer>) -> &mut Self
pub fn push_box_mut(&mut self, layer: Box<dyn Layer>) -> &mut Self
Mutably append a boxed layer.
Sourcepub fn concat(self, other: impl IntoPacket) -> Self
pub fn concat(self, other: impl IntoPacket) -> Self
Append all layers from another packet.
Sourcepub fn extend(&mut self, other: impl IntoPacket) -> &mut Self
pub fn extend(&mut self, other: impl IntoPacket) -> &mut Self
Mutably append all layers from another packet.
Sourcepub fn pop_typed<T>(&mut self) -> Option<T>where
T: Layer,
pub fn pop_typed<T>(&mut self) -> Option<T>where
T: Layer,
Remove and return the final layer when it has type T.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Return the encoded byte length implied by the current layers.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut dyn Layer>
pub fn get_mut(&mut self, index: usize) -> Option<&mut dyn Layer>
Mutable positional layer access.
Sourcepub fn layers<T>(&self) -> impl Iterator<Item = &T>where
T: Layer,
pub fn layers<T>(&self) -> impl Iterator<Item = &T>where
T: Layer,
All layers of type T, preserving packet order.
Sourcepub fn layers_mut<T>(&mut self) -> impl Iterator<Item = &mut T>where
T: Layer,
pub fn layers_mut<T>(&mut self) -> impl Iterator<Item = &mut T>where
T: Layer,
All mutable layers of type T, preserving packet order.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut dyn Layer>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut dyn Layer>
Ordered mutable layer iteration.
Sourcepub fn compile(&self) -> Result<CompiledPacket>
pub fn compile(&self) -> Result<CompiledPacket>
Compile the packet into deterministic bytes.
Sourcepub fn compile_into(&self, out: &mut Vec<u8>) -> Result<()>
pub fn compile_into(&self, out: &mut Vec<u8>) -> Result<()>
Append compiled bytes into an existing buffer.
Sourcepub fn decode_raw(bytes: impl AsRef<[u8]>) -> Result<Self>
pub fn decode_raw(bytes: impl AsRef<[u8]>) -> Result<Self>
Decode bytes as raw payload.
Sourcepub fn decode_from_link(
link_type: LinkType,
bytes: impl AsRef<[u8]>,
) -> Result<Self>
pub fn decode_from_link( link_type: LinkType, bytes: impl AsRef<[u8]>, ) -> Result<Self>
Decode bytes from a link-layer entrypoint.
Sourcepub fn decode_from_link_with_registry(
registry: &ProtocolRegistry,
link_type: LinkType,
bytes: impl AsRef<[u8]>,
) -> Result<Self>
pub fn decode_from_link_with_registry( registry: &ProtocolRegistry, link_type: LinkType, bytes: impl AsRef<[u8]>, ) -> Result<Self>
Decode bytes from a link-layer entrypoint using an explicit registry.
Sourcepub fn decode_from_l3(
network_layer: NetworkLayer,
bytes: impl AsRef<[u8]>,
) -> Result<Self>
pub fn decode_from_l3( network_layer: NetworkLayer, bytes: impl AsRef<[u8]>, ) -> Result<Self>
Decode bytes from a network-layer entrypoint.
Sourcepub fn decode_from_l3_with_registry(
registry: &ProtocolRegistry,
network_layer: NetworkLayer,
bytes: impl AsRef<[u8]>,
) -> Result<Self>
pub fn decode_from_l3_with_registry( registry: &ProtocolRegistry, network_layer: NetworkLayer, bytes: impl AsRef<[u8]>, ) -> Result<Self>
Decode bytes from a network-layer entrypoint using an explicit registry.
Sourcepub fn show(&self) -> String
pub fn show(&self) -> String
Multi-line packet tree intended for display in examples and tools.
Sourcepub fn raw_string_lossy(&self) -> Result<String>
pub fn raw_string_lossy(&self) -> Result<String>
Compile and return raw bytes as a lossy UTF-8 string.