OptionHeader

Struct OptionHeader 

Source
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>

Source

pub const LENGTH: usize = 4usize

Option header wire format size in bytes.

Source

pub fn new_unchecked(buffer: T) -> Self

Create an OptionHeader without validation.

§Parameters
  • buffer - The buffer containing the 4-byte header
§Safety

This does not validate buffer length. Use new_checked for validation.

Source

pub fn new_checked(buffer: T) -> Result<Self>

Create an OptionHeader from a buffer with length validation.

§Parameters
  • buffer - The buffer containing the 4-byte header
§Returns
  • Ok(OptionHeader) if buffer is at least 4 bytes
  • Err(Error) if buffer is too short
Source

pub fn check_len(&self) -> Result<()>

Validate that the buffer is at least 4 bytes long.

§Returns
  • Ok(()) if buffer meets minimum length requirement
  • Err(Error) if buffer is too short
Source

pub fn check_option_type(&self) -> Result<()>

Validate the option type field contains a known option type.

§Returns
  • Ok(()) if option type is valid
  • Err(Error::InvalidOptionType) if option type is unknown
Source

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)

Source

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)

Source

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>

Source

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)
Source

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)
Source

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>

Source§

fn clone(&self) -> OptionHeader<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + AsRef<[u8]>> Debug for OptionHeader<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy + AsRef<[u8]>> Copy for OptionHeader<T>

Auto Trait Implementations§

§

impl<T> Freeze for OptionHeader<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OptionHeader<T>
where T: RefUnwindSafe,

§

impl<T> Send for OptionHeader<T>
where T: Send,

§

impl<T> Sync for OptionHeader<T>
where T: Sync,

§

impl<T> Unpin for OptionHeader<T>
where T: Unpin,

§

impl<T> UnwindSafe for OptionHeader<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.