class PacketBuffer
Defined at line 95 of file gen/third_party/openweave-core/src/include/SystemLayer/SystemPacketBuffer.h
The packet buffer class is the core structure used for manipulating packets of octet-serialized data, usually in the
context of a data communications network, like Bluetooth or the Internet protocol.
In LwIP-based environments, this class is built on top of the pbuf structure defined in that library. In the absence of
LwIP, Weave provides either a malloc-based implementation, or a pool-based implementation that closely approximates the
memory challenges of deeply embedded devices.
The PacketBuffer class, like many similar structures used in layered network stacks, provide a mechanism to reserve space
for protocol headers at each layer of a configurable communication stack. For details, see `PacketBuffer::New()` as well
as LwIP documentation.
PacketBuffer objects are reference-counted, and the prevailing usage mode within Weave is "fire-and-forget". As the packet
(and its underlying PacketBuffer object) is dispatched through various protocol layers, the successful upcall or downcall
between layers implies ownership transfer, and the callee is responsible for freeing the buffer. On failure of a
cross-layer call, the responsibilty for freeing the buffer rests with the caller.
New objects of PacketBuffer class are initialized at the beginning of an allocation of memory obtained from the underlying
environment, e.g. from LwIP pbuf target pools, from the standard C library heap, from an internal buffer pool. In the
simple case, the size of the data buffer is #WEAVE_SYSTEM_PACKETBUFFER_SIZE. A composer is provided that permits usage of
data buffers of other sizes.
PacketBuffer objects may be chained to accomodate larger payloads. Chaining, however, is not transparent, and users of the
class must explicitly decide to support chaining. Examples of classes written with chaining support are as follows:
Public Methods
size_t AllocSize ()
Return the size of the allocation including the reserved and payload data spaces but not including space
allocated for the PacketBuffer structure.
Returns
size of the allocation
Defined at line 215 of file gen/third_party/openweave-core/src/include/SystemLayer/SystemPacketBuffer.h
uint8_t * Start ()
void SetStart (uint8_t * aNewStart)
uint16_t DataLength ()
void SetDataLength (uint16_t aNewLen, PacketBuffer * aChainHead)
uint16_t TotalLength ()
uint16_t MaxDataLength ()
uint16_t AvailableDataLength ()
uint16_t ReservedSize ()
PacketBuffer * Next ()
void AddToEnd (PacketBuffer * aPacket)
PacketBuffer * DetachTail ()
void CompactHead ()
PacketBuffer * Consume (uint16_t aConsumeLength)
void ConsumeHead (uint16_t aConsumeLength)
bool EnsureReservedSize (uint16_t aReservedSize)
bool AlignPayload (uint16_t aAlignBytes)
void AddRef ()
PacketBuffer * NewWithAvailableSize (size_t aAvailableSize)
PacketBuffer * NewWithAvailableSize (uint16_t aReservedSize, size_t aAvailableSize)
PacketBuffer * New ()
PacketBuffer * New (uint16_t aReservedSize)
PacketBuffer * RightSize (PacketBuffer * aPacket)
void Free (PacketBuffer * aPacket)
PacketBuffer * FreeHead (PacketBuffer * aPacket)