pub struct GenericLayer {
pub index: LayerIndex,
pub name: Arc<str>,
pub field_descs: Arc<Vec<GenericFieldDesc>>,
}Expand description
A dynamically-defined protocol layer for custom / user-defined protocols.
The field descriptors are shared (Arc) so they can be defined once and
reused across many packet instances efficiently.
Fields§
§index: LayerIndexPosition of this layer within the packet buffer.
name: Arc<str>Protocol name as defined by the caller.
field_descs: Arc<Vec<GenericFieldDesc>>Shared field descriptors.
Implementations§
Source§impl GenericLayer
impl GenericLayer
Sourcepub fn new(
index: LayerIndex,
name: Arc<str>,
field_descs: Arc<Vec<GenericFieldDesc>>,
) -> Self
pub fn new( index: LayerIndex, name: Arc<str>, field_descs: Arc<Vec<GenericFieldDesc>>, ) -> Self
Create a new GenericLayer.
Sourcepub fn header_len(&self, _buf: &[u8]) -> usize
pub fn header_len(&self, _buf: &[u8]) -> usize
Header length = sum of all field sizes.
Sourcepub fn field_names_dynamic(&self) -> Vec<String>
pub fn field_names_dynamic(&self) -> Vec<String>
Dynamic list of field names (not &'static str because names come from
user-defined strings at runtime).
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Read a field from the buffer.
Returns:
Some(Ok(value))if the field was found and the buffer is long enough.Some(Err(e))if the field was found but the buffer is too short.Noneif no field with this name exists in this layer.
Sourcepub fn set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Write a field into the (mutable) buffer.
Returns:
Some(Ok(()))if the field was found and written successfully.Some(Err(e))if the field was found but the buffer is too short or the value type is wrong.Noneif no field with this name exists in this layer.
Trait Implementations§
Source§impl Clone for GenericLayer
impl Clone for GenericLayer
Source§fn clone(&self) -> GenericLayer
fn clone(&self) -> GenericLayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GenericLayer
impl Debug for GenericLayer
Source§impl Layer for GenericLayer
impl Layer for GenericLayer
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
The Layer trait requires &'static [&'static str], which is not
possible for dynamically-generated field names. Returns an empty
slice; callers that need the full list should call
field_names_dynamic directly.