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§
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> 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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