pub struct OptionHeader<T: AsRef<[u8]>> { /* private fields */ }Expand description
Zero-copy wrapper around Option header (4 bytes).
All SOME/IP-SD options start with this 4-byte header containing the length, type, and discardable flag.
Wire format (4 bytes):
0 1 2 3
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |D| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Implementations§
Source§impl<T: AsRef<[u8]>> OptionHeader<T>
impl<T: AsRef<[u8]>> OptionHeader<T>
Sourcepub fn new_unchecked(buffer: T) -> Self
pub fn new_unchecked(buffer: T) -> Self
Sourcepub fn new_checked(buffer: T) -> Result<Self>
pub fn new_checked(buffer: T) -> Result<Self>
Sourcepub fn check_len(&self) -> Result<()>
pub fn check_len(&self) -> Result<()>
Validate that the buffer is at least 4 bytes long.
§Returns
Ok(())if buffer meets minimum length requirementErr(Error)if buffer is too short
Sourcepub fn check_option_type(&self) -> Result<()>
pub fn check_option_type(&self) -> Result<()>
Validate the option type field contains a known option type.
§Returns
Ok(())if option type is validErr(Error::InvalidOptionType)if option type is unknown
Sourcepub fn length(&self) -> u16
pub fn length(&self) -> u16
Get the Length field (2 bytes at offset 0-1, network byte order).
§Returns
Length of the option data (excluding the 4-byte header itself)
Sourcepub fn option_type(&self) -> u8
pub fn option_type(&self) -> u8
Get the Type field (1 byte at offset 2).
§Returns
Option type value (use OptionType::from_u8 to parse)
Sourcepub fn discardable_flag(&self) -> DiscardableFlag
pub fn discardable_flag(&self) -> DiscardableFlag
Get the Discardable flag and reserved bits (1 byte at offset 3).
§Returns
DiscardableFlag containing the discardable bit and reserved bits
Source§impl<T: AsRef<[u8]> + AsMut<[u8]>> OptionHeader<T>
impl<T: AsRef<[u8]> + AsMut<[u8]>> OptionHeader<T>
Sourcepub fn set_length(&mut self, value: u16)
pub fn set_length(&mut self, value: u16)
Set the Length field (2 bytes at offset 0-1, network byte order).
§Parameters
value- Length of option data (excluding the 4-byte header)
Sourcepub fn set_option_type(&mut self, value: u8)
pub fn set_option_type(&mut self, value: u8)
Set the Type field (1 byte at offset 2).
§Parameters
value- Option type value (use OptionType::as_u8 for enum values)
Sourcepub fn set_discardable_flag(&mut self, value: DiscardableFlag)
pub fn set_discardable_flag(&mut self, value: DiscardableFlag)
Set the Discardable flag and reserved bits (1 byte at offset 3).
§Parameters
value- DiscardableFlag with the desired bit pattern
Trait Implementations§
Source§impl<T: Clone + AsRef<[u8]>> Clone for OptionHeader<T>
impl<T: Clone + AsRef<[u8]>> Clone for OptionHeader<T>
Source§fn clone(&self) -> OptionHeader<T>
fn clone(&self) -> OptionHeader<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more