![]() |
Morse Micro IoT SDK
2.9.7
|
This API provides support for buffers tailored towards packets.
Data Structures | |
| union | mmpkt_metadata_ptr |
| Union of pointer types for mmpkt metadata. More... | |
| struct | mmpkt |
| Core mmpkt data structure. More... | |
| struct | mmpkt_ops |
| Operations data structure for mmpkt. More... | |
| struct | mmpkt_list |
| Structure that can be used as the head of a linked list of mmpkts that counts its length. More... | |
Macros | |
| #define | MM_FAST_ROUND_UP(x, m) ((((x)-1) | ((m)-1)) + 1) |
Round x up to the next multiple of m (where m is a power of 2). More... | |
Functions | |
| static void | mmpkt_init (struct mmpkt *mmpkt, uint8_t *buf, uint32_t buf_len, uint32_t data_start_offset, const struct mmpkt_ops *ops) |
| Initialize an mmpkt header with the given values. More... | |
| static struct mmpkt * | mmpkt_init_buf (uint8_t *buf, uint32_t buf_len, uint32_t space_at_start, uint32_t space_at_end, uint32_t metadata_size, const struct mmpkt_ops *ops) |
| Initialize an mmpkt in a single buffer using the given values. More... | |
| struct mmpkt * | mmpkt_alloc_on_heap (uint32_t space_at_start, uint32_t space_at_end, uint32_t metadata_size) |
| Allocate a new mmpkt on the heap (using mmosal_malloc()). More... | |
| void | mmpkt_release (struct mmpkt *mmpkt) |
| Release a reference to the given mmpkt. More... | |
| static struct mmpktview * | mmpkt_open (struct mmpkt *mmpkt) |
| Open a view of the given mmpkt. More... | |
| static void | mmpkt_close (struct mmpktview **view) |
| Close the given view. More... | |
| static struct mmpkt * | mmpkt_from_view (struct mmpktview *view) |
| Get the underlying mmpkt from an opened view. More... | |
| static uint8_t * | mmpkt_get_data_start (struct mmpktview *view) |
| Gets a pointer to the start of the data in the mmpkt. More... | |
| static uint8_t * | mmpkt_get_data_end (struct mmpktview *view) |
| Gets a pointer to the end of the data in the mmpkt. More... | |
| static uint32_t | mmpkt_peek_data_length (struct mmpkt *mmpkt) |
| Peek the length of the data currently from an unopened mmpkt. More... | |
| static uint32_t | mmpkt_get_data_length (struct mmpktview *view) |
| Gets the length of the data currently in the mmpkt. More... | |
| static uint32_t | mmpkt_available_space_at_start (struct mmpktview *view) |
| Returns the amount of space available for prepending to the data in the buffer. More... | |
| static uint32_t | mmpkt_available_space_at_end (struct mmpktview *view) |
| Returns the amount of space available for appending to the data in the buffer. More... | |
| static uint8_t * | mmpkt_prepend (struct mmpktview *view, uint32_t len) |
| Reserves space immediately before the data currently in the given mmpkt and returns a pointer to this space. More... | |
| static void | mmpkt_prepend_data (struct mmpktview *view, const uint8_t *data, uint32_t len) |
| Prepends the given data to the data already in the mmpkt. More... | |
| static uint8_t * | mmpkt_append (struct mmpktview *view, uint32_t len) |
| Reserves space immediately after the data currently in the given mmpkt and returns a pointer to this space. More... | |
| static void | mmpkt_append_data (struct mmpktview *view, const uint8_t *data, uint32_t len) |
| Appends the given data to the data already in the mmpkt. More... | |
| static union mmpkt_metadata_ptr | mmpkt_get_metadata (struct mmpkt *mmpkt) |
| Retrieve a reference to the metadata associated with the given mmpkt. More... | |
| static void | mmpkt_adjust_start_offset (struct mmpkt *mmpkt, int32_t delta) |
| Adjust the start offset of an mmpkt. More... | |
| static uint8_t * | mmpkt_remove_from_start (struct mmpktview *view, uint32_t len) |
| Remove data from the start of the mmpkt. More... | |
| static uint8_t * | mmpkt_remove_from_end (struct mmpktview *view, uint32_t len) |
| Remove data from the end of the mmpkt. More... | |
| static void | mmpkt_truncate (struct mmpkt *mmpkt, uint32_t len) |
| Truncate the mmpkt data to the given length. More... | |
| static struct mmpkt * | mmpkt_get_next (struct mmpkt *mmpkt) |
Get the next pointer embedded in the mmpkt. More... | |
| static void | mmpkt_set_next (struct mmpkt *mmpkt, struct mmpkt *next) |
Set the next pointer embedded in the mmpkt. More... | |
| static bool | mmpkt_contains_ptr (struct mmpktview *view, const void *ptr) |
| Check whether the given pointer is pointing inside the mmpkt's buffer. More... | |
| #define MM_FAST_ROUND_UP | ( | x, | |
| m | |||
| ) | ((((x)-1) | ((m)-1)) + 1) |
|
inlinestatic |
Adjust the start offset of an mmpkt.
This is only allowable when the mmpkt is empty (i.e., data_len is 0).
| mmpkt | The mmpkt to operate on. |
| delta | Difference between the current start offset and the new start offset (this may be negative, but the new start offset must not be less than 0). |
| struct mmpkt * mmpkt_alloc_on_heap | ( | uint32_t | space_at_start, |
| uint32_t | space_at_end, | ||
| uint32_t | metadata_size | ||
| ) |
Allocate a new mmpkt on the heap (using mmosal_malloc()).
| space_at_start | Amount of space to reserve at start of buffer. |
| space_at_end | Amount of space to reserve at end of buffer. |
| metadata_size | Size of metadata (0 for no metadata). |
start_offset will be set to space_at_start, and buf_len will be the sum of space_at_start and space_at_end (rounded up to a multiple of 4).NULL on failure.
|
inlinestatic |
Reserves space immediately after the data currently in the given mmpkt and returns a pointer to this space.
For a function that also copies data in, see mmpkt_append_data().
len must be less than or equal to mmpkt_available_space_at_end().| view | The opened mmpkt to operate on. |
| len | Length of data to be append. |
|
inlinestatic |
Appends the given data to the data already in the mmpkt.
len must be less than or equal to mmpkt_available_space_at_start().| view | The opened mmpkt to operate on. |
| data | The data to be prepended. |
| len | Length of data to be prepended. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Check whether the given pointer is pointing inside the mmpkt's buffer.
| view | The opened mmpkt to operate on. |
| ptr | The pointer to check. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Get the next pointer embedded in the mmpkt.
Used by the mmpkt_list structure for making linked lists of mmpkts.
| mmpkt | The mmpkt to operate on. |
|
inlinestatic |
Initialize an mmpkt in a single buffer using the given values.
| buf | Pointer to buffer. |
| buf_len | Length of buf. |
| space_at_start | Amount of space to reserve at start of buffer. |
| space_at_end | Amount of space to reserve at end of buffer. |
| metadata_size | Size of metadata (0 for no metadata). |
| ops | Operations data structure. |
buf_len must be large enough to contain the mmkpt header, the data buffer (rounded up to the nearest 4 bytes) and metadata (rounded up to the nearest 4 bytes).mmpkt (will be the same address as buf) or NULL on error (buf length too short).
|
inlinestatic |
Open a view of the given mmpkt.
Packets must be opened before the contents of their buffer can be accessed. Most of the functions below expect to be passed an opened view of a packet to operate on.
The view must be closed by calling mmpkt_close() before the packet is released by mmpkt_release().
| mmpkt | The mmpkt to be opened. |
|
inlinestatic |
|
inlinestatic |
Reserves space immediately before the data currently in the given mmpkt and returns a pointer to this space.
For a function that also copies data in, see mmpkt_prepend_data().
len must be less than or equal to mmpkt_available_space_at_start().| view | The opened mmpkt to operate on. |
| len | Length of data to be prepended. |
|
inlinestatic |
Prepends the given data to the data already in the mmpkt.
len must be less than or equal to mmpkt_available_space_at_start().| view | The opened mmpkt to operate on. |
| data | The data to be prepended. |
| len | Length of data to be prepended. |
| void mmpkt_release | ( | struct mmpkt * | mmpkt | ) |
Release a reference to the given mmpkt.
If this was the last reference (addition_ref_cnt was 0) then the mmpkt will be freed using the appropriate op callback.
| mmpkt | The mmpkt to release reference to. May be NULL. |
|
inlinestatic |
|
inlinestatic |
Set the next pointer embedded in the mmpkt.
Used by the mmpkt_list structure for making linked lists of mmpkts.
| mmpkt | The mmpkt to operate on. |
| next | The next mmpkt in the chain. |