leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Embed: (wiki syntax)

« Back to documentation index

Packet Class Reference

Received packet. More...

#include <Packet.h>

Public Member Functions

uint32_t size () const
 Size of the packet.
uint32_t len () const
 Amount of data store in the packet.
const char * data () const
 Pointer to the internal buffer.
Packetnext () const
 Pointer to the next packet in the chain or NULL if none.
uint32_t append (const char *data, uint32_t len)
 Appends up to `len` bytes from `data` into this packet and returns the number of bytes copied.
uint32_t consume (char *data, uint32_t len)
 Consumes up to `len` bytes from this packet in to `data`.
void set_next (Packet *next)
 Sets the pointer to next target.
 ~Packet ()
 Deletes this packet and its following packets in the chain.

Static Public Member Functions

static Packetnew_packet (uint32_t size, volatile uint32_t &heap_usage)
 Creates a new packet tracking memory usage in heap_usage.

Detailed Description

Received packet.

Warning:
Packets keep a reference into their source network interface. They shall never outlive this interface.

Definition at line 27 of file Packet.h.


Constructor & Destructor Documentation

~Packet (  )

Deletes this packet and its following packets in the chain.

Warning:
it is unsafe to delete a packet that is referenced by another packet.

Definition at line 75 of file Packet.cpp.


Member Function Documentation

uint32_t append ( const char *  data,
uint32_t  len 
)

Appends up to `len` bytes from `data` into this packet and returns the number of bytes copied.

Parameters:
dataSource buffer.
lenSource length.
Returns:
number of bytes copied.

Definition at line 41 of file Packet.cpp.

uint32_t consume ( char *  data,
uint32_t  len 
)

Consumes up to `len` bytes from this packet in to `data`.

Parameters:
dataOutput buffer.
lenOutput buffer length.
Returns:
number of bytes copied into `data`.

Definition at line 53 of file Packet.cpp.

const char* data (  ) const

Pointer to the internal buffer.

Definition at line 56 of file Packet.h.

uint32_t len (  ) const

Amount of data store in the packet.

Definition at line 49 of file Packet.h.

Packet * new_packet ( uint32_t  size,
volatile uint32_t &  heap_usage 
) [static]

Creates a new packet tracking memory usage in heap_usage.

Parameters:
sizeSize of the packet.
heap_usagereference to a volatile long integer thread safely keeping track of the memory usage.
Returns:
A new packet or NULL on failure.

Definition at line 21 of file Packet.cpp.

Packet* next (  ) const

Pointer to the next packet in the chain or NULL if none.

Definition at line 63 of file Packet.h.

void set_next ( Packet next )

Sets the pointer to next target.

Note:
Setting to NULL will not delete the next packet but simply detach it.

Definition at line 66 of file Packet.cpp.

uint32_t size (  ) const

Size of the packet.

Definition at line 42 of file Packet.h.