Struct riot_wrappers::gnrc_pktbuf::Pktsnip
source · pub struct Pktsnip<M: Mode> { /* private fields */ }
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
).
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
and 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_gnrc
and riot_module_ipv6
only.
pub fn ipv6_get_header(&self) -> Option<&Header>
riot_module_gnrc
and 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_gnrc
and riot_module_ipv6
only.
pub fn ipv6_hdr_build( self, src: Option<&Address>, dst: Option<&Address> ) -> Result<Pktsnip<Writable>, NotEnoughSpace>
riot_module_gnrc
and riot_module_ipv6
only.Build an IPv6 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.
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.