pub struct Pktsnip<M: Mode> {
pub(crate) ptr: *mut gnrc_pktsnip_t,
_phantom: PhantomData<M>,
}
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>
impl<'a> Pktsnip<Writable>
pub fn icmpv6_echo_build( type_: EchoType, id: u16, seq: u16, payload: &[u8], ) -> Result<Pktsnip<Writable>, NotEnoughSpace>
riot_module_gnrc_icmpv6
only.Source§impl<M: Mode> Pktsnip<M>
impl<M: Mode> Pktsnip<M>
Sourcepub fn ipv6_get_header(&self) -> Option<&Header>
Available on riot_module_ipv6
only.
pub fn ipv6_get_header(&self) -> Option<&Header>
riot_module_ipv6
only.Get the IPv6 header of the snip, if there is any thusly typed snip present
Sourcepub fn ipv6_hdr_build(
self,
src: Option<&Address>,
dst: Option<&Address>,
) -> Result<Pktsnip<Writable>, NotEnoughSpace>
Available on riot_module_ipv6
only.
pub fn ipv6_hdr_build( self, src: Option<&Address>, dst: Option<&Address>, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>
riot_module_ipv6
only.Build an IPv6 header around the Pktsnip
Source§impl<M: Mode> Pktsnip<M>
impl<M: Mode> Pktsnip<M>
Sourcepub fn netif_get_header(&self) -> Option<Header<'_>>
pub fn netif_get_header(&self) -> Option<Header<'_>>
Get the Netif header of the snip, if there is any thusly typed snip present
Sourcepub fn netif_hdr_builder(self) -> HeaderBuilder<M>
pub fn netif_hdr_builder(self) -> HeaderBuilder<M>
Build a netif header around the Pktsnip
Source§impl<M: Mode> Pktsnip<M>
impl<M: Mode> Pktsnip<M>
pub fn len(&self) -> usize
pub fn count(&self) -> usize
pub fn iter_snips(&self) -> SnipIter<'_> ⓘ
pub fn search_type(&self, type_: gnrc_nettype_t) -> Option<PktsnipPart<'_>>
Sourcepub unsafe fn to_ptr(self) -> *mut gnrc_pktsnip_t
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.
Sourcepub fn udp_hdr_build(
self,
src: NonZeroU16,
dst: NonZeroU16,
) -> Result<Pktsnip<Writable>, NotEnoughSpace>
Available on riot_module_udp
only.
pub fn udp_hdr_build( self, src: NonZeroU16, dst: NonZeroU16, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>
riot_module_udp
only.Build a UDP header around the Pktsnip
pub fn netif_hdr_build( self, src: Option<&[u8]>, dst: Option<&[u8]>, ) -> Result<Pktsnip<Writable>, NotEnoughSpace>
Sourcepub fn add(
self,
size: usize,
nettype: gnrc_nettype_t,
) -> Result<Pktsnip<Writable>, NotEnoughSpace>
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.
Sourcepub unsafe fn from_ptr(input: *mut gnrc_pktsnip_t) -> Self
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.
Sourcepub fn start_write(self) -> Result<Pktsnip<Writable>, NotEnoughSpace>
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>
impl<'a> Pktsnip<Writable>
Sourcepub unsafe fn from_ptr(input: *mut gnrc_pktsnip_t) -> Self
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.
Sourcepub fn allocate(
size: usize,
nettype: gnrc_nettype_t,
) -> Result<Self, NotEnoughSpace>
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).
Sourcepub fn allocate_from(
data: &[u8],
nettype: gnrc_nettype_t,
) -> Result<Self, NotEnoughSpace>
pub fn allocate_from( data: &[u8], nettype: gnrc_nettype_t, ) -> Result<Self, NotEnoughSpace>
Allocate a pktsnip and copy the slice into it.
Sourcefn _add(
next: Option<Pktsnip<impl Mode>>,
data: *const u8,
size: usize,
nettype: gnrc_nettype_t,
) -> Result<Self, NotEnoughSpace>
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.
pub fn data_mut(&'a mut self) -> &'a mut [u8]
pub fn realloc_data(&mut self, size: usize) -> Result<(), NotEnoughSpace>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoSwitch for T
impl<T> IntoSwitch for T
Source§fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
fn into_switch<ActiveLevel>(self) -> Switch<T, ActiveLevel>
Source§fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
fn into_active_high_switch(self) -> Switch<Self, ActiveHigh>where
Self: Sized,
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