Skip to main content

PacketView

Struct PacketView 

Source
pub struct PacketView<'a> { /* private fields */ }
Expand description

A zero-copy view into a raw packet buffer.

PacketView does not own the underlying data. It simply interprets a byte slice according to the expected packet layout.

This is useful in embedded or no_std environments where copying or allocating packets is undesirable.

§Packet layout

The expected layout of the underlying buffer is assumed to be:

+----------------+----------------+----------------+
| MAC (6 bytes)  | FLAGS (1 byte) | NONCE (5 bytes) | ...
+----------------+----------------+----------------+

Offsets are defined by constants such as MAC_OFFSET, FLAGS_IDX, and NONCE_OFFSET.

§Safety / Panics

This type uses unwrap() internally when extracting fixed-size fields. Therefore:

  • The input slice must be large enough
  • Invalid or truncated buffers will cause a panic

In embedded contexts, ensure packet validation happens before constructing a PacketView.

Implementations§

Source§

impl<'a> PacketView<'a>

Source

pub fn new(bytes: &'a [u8]) -> Result<Self, Error>

Creates a new PacketView from a raw byte slice.

This performs basic validation via TryFrom<[u8]> implementation.

§Errors

Returns PacketError if the buffer is too small or malformed.

Source

pub fn mac(&self) -> [u8; 6]

Returns the 6-byte MAC address from the packet.

Source

pub fn flags(&self) -> u8

Returns the packet flags byte.

Source

pub fn raw_nonce(&self) -> [u8; 5]

Returns the raw 5-byte nonce field.

Source

pub fn nonce(&self) -> u64

Returns the raw nonce as a 64-bit integer in be format.

Trait Implementations§

Source§

impl<'a> TryFrom<&'a [u8]> for PacketView<'a>

Source§

fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>

Attempts to parse a slice of over-the-air bytes into an organized packet view layout.

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl<'a> Freeze for PacketView<'a>

§

impl<'a> RefUnwindSafe for PacketView<'a>

§

impl<'a> Send for PacketView<'a>

§

impl<'a> Sync for PacketView<'a>

§

impl<'a> Unpin for PacketView<'a>

§

impl<'a> UnsafeUnpin for PacketView<'a>

§

impl<'a> UnwindSafe for PacketView<'a>

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