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

🔬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