Trait nrf_softdevice::ble::l2cap::Packet
source · pub trait Packet: Sized {
const MTU: usize;
// Required methods
fn allocate() -> Option<NonNull<u8>>;
fn into_raw_parts(self) -> (NonNull<u8>, usize);
unsafe fn from_raw_parts(ptr: NonNull<u8>, len: usize) -> Self;
}
Expand description
A Packet is a byte buffer for packet data.
Similar to a Vec<u8>
it has a length and a capacity.
The capacity however is the fixed value MTU
.
You need to implement this trait to give the L2CAP driver a method to allocate and free the space for the packets sent and received on a channel.
Required Associated Constants§
Required Methods§
sourcefn allocate() -> Option<NonNull<u8>>
fn allocate() -> Option<NonNull<u8>>
Allocate a new buffer with space for MTU
bytes.
Return None
when the allocation can’t be fulfilled.
This function is called by the L2CAP driver when it needs
space to receive a packet into.
It will later call from_raw_parts
with the buffer and the
amount of bytes it has received.
sourcefn into_raw_parts(self) -> (NonNull<u8>, usize)
fn into_raw_parts(self) -> (NonNull<u8>, usize)
Take ownership of the packet buffer. Returns a pointer to the buffer and the number of bytes in the buffer.
To free the memory the driver will call from_raw_parts
later
and drop the value.
sourceunsafe fn from_raw_parts(ptr: NonNull<u8>, len: usize) -> Self
unsafe fn from_raw_parts(ptr: NonNull<u8>, len: usize) -> Self
Construct a Packet
from a pointer to a buffer and the number of bytes
written to the buffer.
SAFETY: ptr
must be a pointer previously returned by either
allocate
or ìnto_raw_parts
.
len
must be the number of bytes in the buffer and must not be larger
than MTU
.