pub struct PcapNGOption<'a> {
pub code: OptionCode,
pub len: u16,
pub value: Cow<'a, [u8]>,
}
Expand description
A PcapNG option
Fields§
§code: OptionCode
The numeric code for the option
Note that codes are relative to the block type, and same codes are used for different
things (for ex 2 is shb_hardware
if the block is a SHB, but 2 is if_name
for an IDB)
len: u16
The declared length for the option
Note that value.len()
can be greater than len
, because data is padded to a 32-bit boundary
value: Cow<'a, [u8]>
The raw value (including padding) of the option
See PcapNGOption::as_bytes to get the value truncated to len
.
Implementations§
Source§impl PcapNGOption<'_>
impl PcapNGOption<'_>
Sourcepub fn value(&self) -> &[u8] ⓘ
pub fn value(&self) -> &[u8] ⓘ
Return a reference to the option value, as raw bytes (not related to the len
field)
Sourcepub fn as_bytes(&self) -> Result<&[u8], PcapNGOptionError>
pub fn as_bytes(&self) -> Result<&[u8], PcapNGOptionError>
Return a reference to the option value, using the len
field to limit it, or None if length is invalid
Sourcepub fn as_str(&self) -> Result<&str, PcapNGOptionError>
pub fn as_str(&self) -> Result<&str, PcapNGOptionError>
Return the option value interpreted as string
Returns an error if the length of the option is invalid, or if the value is not valid UTF-8.
Sourcepub fn as_i32_le(&self) -> Result<i32, PcapNGOptionError>
pub fn as_i32_le(&self) -> Result<i32, PcapNGOptionError>
Return the option value interpreted as i32, or an error
Option data length and declared must be exactly 4 bytes
Sourcepub fn as_u32_le(&self) -> Result<u32, PcapNGOptionError>
pub fn as_u32_le(&self) -> Result<u32, PcapNGOptionError>
Return the option value interpreted as u32, or an error
Option data length and declared must be exactly 4 bytes
Sourcepub fn as_i64_le(&self) -> Result<i64, PcapNGOptionError>
pub fn as_i64_le(&self) -> Result<i64, PcapNGOptionError>
Return the option value interpreted as i64, or an error
Option data length and declared must be exactly 8 bytes
Sourcepub fn as_u64_le(&self) -> Result<u64, PcapNGOptionError>
pub fn as_u64_le(&self) -> Result<u64, PcapNGOptionError>
Return the option value interpreted as u64, or an error
Option data length and declared must be exactly 8 bytes
Trait Implementations§
Source§impl<'a> Debug for PcapNGOption<'a>
impl<'a> Debug for PcapNGOption<'a>
Source§impl ToVec for PcapNGOption<'_>
Available on crate feature serialize
only.
impl ToVec for PcapNGOption<'_>
serialize
only.