riot_wrappers::gnrc_pktbuf

Struct Pktsnip

source
pub struct Pktsnip<M: Mode> {
    pub(crate) ptr: *mut gnrc_pktsnip_t,
    _phantom: PhantomData<M>,
}
Available on riot_module_gnrc_pktbuf only.
Expand description

Wrapper type around gnrc_pktsnip_t that takes care of the reference counting involved.

By constructing a Pktsnip, it is also asserted that any snip annotations are correct (for example, that a GNRC_NETTYPE_IPV6 snip does contain a full IPv6 header, as demanded by gnrc_ipv6_get_header).

Fields§

§ptr: *mut gnrc_pktsnip_t§_phantom: PhantomData<M>

Implementations§

source§

impl<'a> Pktsnip<Writable>

source

pub fn icmpv6_echo_build( type_: EchoType, id: u16, seq: u16, payload: &[u8], ) -> Result<Pktsnip<Writable>, NotEnoughSpace>

Available on riot_module_gnrc_icmpv6 only.
source§

impl<M: Mode> Pktsnip<M>

source

pub fn ipv6_get_header(&self) -> Option<&Header>

Available on riot_module_ipv6 only.

Get the IPv6 header of the snip, if there is any thusly typed snip present

source

pub fn ipv6_hdr_build( self, src: Option<&Address>, dst: Option<&Address>, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>

Available on riot_module_ipv6 only.

Build an IPv6 header around the Pktsnip

source§

impl<M: Mode> Pktsnip<M>

source

pub fn netif_get_header(&self) -> Option<Header<'_>>

Get the Netif header of the snip, if there is any thusly typed snip present

source

pub fn netif_hdr_builder(self) -> HeaderBuilder<M>

Build a netif header around the Pktsnip

source§

impl<M: Mode> Pktsnip<M>

source

pub fn len(&self) -> usize

source

pub fn count(&self) -> usize

source

pub fn iter_snips(&self) -> SnipIter<'_>

source

pub fn search_type(&self, type_: gnrc_nettype_t) -> Option<PktsnipPart<'_>>

source

pub fn data(&self) -> &[u8]

Return the data of only the first snip of self.

source

pub unsafe fn to_ptr(self) -> *mut gnrc_pktsnip_t

Relinquish the safe Pktsnip into a pointer. The caller is responsible for calling gnrc_pktbuf_release on the result, or passing it on to someone who will.

This is not technically unsafe as it leaks the item to get a pointer out; it’s left unsafe more as a warning flag.

source

pub fn udp_hdr_build( self, src: NonZeroU16, dst: NonZeroU16, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>

Available on riot_module_udp only.

Build a UDP header around the Pktsnip

source

pub fn netif_hdr_build( self, src: Option<&[u8]>, dst: Option<&[u8]>, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>

👎Deprecated: Use netif_hdr_builder instead
source

pub fn add( self, size: usize, nettype: gnrc_nettype_t, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>

Allocate and prepend an uninitialized snip of given size and type to self, returning a new (writable) snip.

source§

impl<'a> Pktsnip<Shared>

source

pub unsafe fn from_ptr(input: *mut gnrc_pktsnip_t) -> Self

Take responsibility for a pointer

The pointer must currently have a refcount of at least 1; dropping the result decrements it.

source

pub fn start_write(self) -> Result<Pktsnip<Writable>, NotEnoughSpace>

Create an exclusive version of this pktsnip

This involves a copy if the current reference count is > 1.

source§

impl<'a> Pktsnip<Writable>

source

pub unsafe fn from_ptr(input: *mut gnrc_pktsnip_t) -> Self

Take responsibility for a pointer

The pointer must currently have a refcount of 1; the buffer is freed when the result is dropped.

source

pub fn allocate( size: usize, nettype: gnrc_nettype_t, ) -> Result<Self, NotEnoughSpace>

Allocate an uninitialized pktsnip. That its data is uninitialized is currently not expressed in Rust as the author thinks it’s harmless (any u8 is a valid u8, and the compiler can’t know that we’re receiving uninitialized memory here so it can’t take any shortcuts if someone ever read from it).

source

pub fn allocate_from( data: &[u8], nettype: gnrc_nettype_t, ) -> Result<Self, NotEnoughSpace>

Allocate a pktsnip and copy the slice into it.

source

fn _add( next: Option<Pktsnip<impl Mode>>, data: *const u8, size: usize, nettype: gnrc_nettype_t, ) -> Result<Self, NotEnoughSpace>

Actual wrapper around gnrc_pktbuf_add. Split into two API functions because .add() makes sense as a method, and with None as next it’s more of a constructor function.

source

pub fn data_mut(&'a mut self) -> &'a mut [u8]

source

pub fn realloc_data(&mut self, size: usize) -> Result<(), NotEnoughSpace>

Trait Implementations§

source§

impl Clone for Pktsnip<Shared>

source§

fn clone(&self) -> Pktsnip<Shared>

Returns a copy 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<M: Mode> Debug for Pktsnip<M>

source§

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

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

impl<M: Mode> Drop for Pktsnip<M>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Into<Pktsnip<Shared>> for Pktsnip<Writable>

source§

fn into(self) -> Pktsnip<Shared>

Converts this type into the (usually inferred) input type.
source§

impl Send for Pktsnip<Shared>

Pktsnip can be send because any volatile fields are accessed through the appropriate functions (hold, release), and the non-volatile fields are only written to by threads that made sure they obtained a COW copy using start_write.

Auto Trait Implementations§

§

impl<M> Freeze for Pktsnip<M>

§

impl<M> RefUnwindSafe for Pktsnip<M>
where M: RefUnwindSafe,

§

impl<M> !Send for Pktsnip<M>

§

impl<M> !Sync for Pktsnip<M>

§

impl<M> Unpin for Pktsnip<M>
where M: Unpin,

§

impl<M> UnwindSafe for Pktsnip<M>
where M: 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoSwitch for T

source§

fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more
source§

fn into_active_low_switch(self) -> Switch<Self, ActiveLow>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more
source§

fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>
where Self: Sized,

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more
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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 4 bytes