Fawkes API
Fawkes Development Version
|
Dynamically growing buffer. More...
#include <>>
Public Member Functions | |
DynamicBuffer (dynamic_list_t *db, size_t initial_buffer_size=1024) | |
Write constructor. More... | |
DynamicBuffer (dynamic_list_t *db, void *buf, size_t size) | |
Read constructor. More... | |
virtual | ~DynamicBuffer () |
Destructor. More... | |
void | append (const void *data, size_t data_size) |
Append data. More... | |
void * | buffer () |
Get pointer to buffer. More... | |
size_t | buffer_size () |
Get buffer size. More... | |
unsigned int | num_elements () |
Get number of elements. More... | |
size_t | real_buffer_size () |
Get real buffer size. More... | |
bool | has_next () |
Check if another element is available. More... | |
void * | next (size_t *size) |
Get next buffer. More... | |
void | reset_iterator () |
Reset iterator. More... | |
Dynamically growing buffer.
This class maintains a list or arbitrary data objects stuffed into one consecutive memory. The buffer layout is like the following: A dynamic_list_t element is supplied and can reside anywhere you like (in the case of the Fawkes network protocol in your static struct). It contains information about the size and number of elements of the list. The list itself is formed by concatenated memory regions, each preceeded by a two byte length value.
The list may be at most 4 GB in total size (including in-between headers) Each list item by itself can be at most 64 KB in size. The buffer starts with an initial size. If this initial size is exceeded the buffer size is doubled. If the double size would exceed 4 GB it is increased to exactly 4 GB.
The numbers in the headers are stored in network byte order and thus are suitable for direct sending over the network.
Definition at line 46 of file dynamic_buffer.h.
fawkes::DynamicBuffer::DynamicBuffer | ( | dynamic_list_t * | db, |
size_t | initial_buffer_size = 1024 |
||
) |
Write constructor.
Use this constructor to create and write to this dynamic buffer.
db | dynamic list header in your message |
initial_buffer_size | initial buffer size to use, by default 1 KB |
Definition at line 64 of file dynamic_buffer.cpp.
References fawkes::dynamic_list_t::num_elements, and fawkes::dynamic_list_t::size.
fawkes::DynamicBuffer::DynamicBuffer | ( | dynamic_list_t * | db, |
void * | buf, | ||
size_t | size | ||
) |
Read constructor.
Use this constructor to read from a dynamic buffer.
db | dynamic list header in the incoming message |
buf | buffer to parse |
size | size of the buffer |
Definition at line 88 of file dynamic_buffer.cpp.
|
virtual |
Destructor.
If in writing mode frees up the buffer.
Definition at line 107 of file dynamic_buffer.cpp.
void fawkes::DynamicBuffer::append | ( | const void * | data, |
size_t | data_size | ||
) |
Append data.
Appends data to the list. Throws an exception if there is not enough memory to hold the data or if in read-only mode.
data | data to append |
data_size | size of the data in bytes |
AccessViolationException | thrown if buffer is in read-only mode |
IllegalArgumentException | thrown if data size is bigger than 64 KB - 2 bytes |
OutOfMemoryException | thrown if no memory could be allocated |
Definition at line 123 of file dynamic_buffer.cpp.
References fawkes::dynamic_list_t::num_elements, and fawkes::dynamic_list_t::size.
Referenced by fawkes::PluginListMessage::append(), fawkes::ConfigListContent::append(), and fawkes::BlackBoardInterfaceListContent::append_interface().
void * fawkes::DynamicBuffer::buffer | ( | ) |
Get pointer to buffer.
Definition at line 159 of file dynamic_buffer.cpp.
Referenced by fawkes::PluginListMessage::serialize(), fawkes::ConfigListContent::serialize(), and fawkes::BlackBoardInterfaceListContent::serialize().
size_t fawkes::DynamicBuffer::buffer_size | ( | ) |
Get buffer size.
Gets the size of the used part of the buffer. The size of the buffer that is really occupied by data.
Definition at line 201 of file dynamic_buffer.cpp.
References fawkes::dynamic_list_t::size.
Referenced by fawkes::PluginListMessage::serialize(), fawkes::ConfigListContent::serialize(), and fawkes::BlackBoardInterfaceListContent::serialize().
bool fawkes::DynamicBuffer::has_next | ( | ) |
Check if another element is available.
Definition at line 245 of file dynamic_buffer.cpp.
References fawkes::dynamic_list_t::num_elements.
Referenced by fawkes::PluginListMessage::has_next(), fawkes::ConfigListContent::has_next(), fawkes::BlackBoardInterfaceListContent::has_next(), and next().
void * fawkes::DynamicBuffer::next | ( | size_t * | size | ) |
Get next buffer.
size | upon successful return contains size of the current list buffer |
OutOfBoundsException | thrown if no further element is available in the list. |
Definition at line 258 of file dynamic_buffer.cpp.
References has_next().
Referenced by fawkes::PluginListMessage::next(), fawkes::ConfigListContent::next(), and fawkes::BlackBoardInterfaceListContent::next().
unsigned int fawkes::DynamicBuffer::num_elements | ( | ) |
Get number of elements.
Definition at line 223 of file dynamic_buffer.cpp.
References fawkes::dynamic_list_t::num_elements.
size_t fawkes::DynamicBuffer::real_buffer_size | ( | ) |
Get real buffer size.
Gets the real size of the buffer including yet unused parts. Meant to be used for debugging or informational usage.
Definition at line 213 of file dynamic_buffer.cpp.
void fawkes::DynamicBuffer::reset_iterator | ( | ) |
Reset iterator.
Definition at line 232 of file dynamic_buffer.cpp.
Referenced by fawkes::PluginListMessage::reset_iterator(), fawkes::ConfigListContent::reset_iterator(), and fawkes::BlackBoardInterfaceListContent::reset_iterator().