Arduino KVComm
master
Key-Value pair communication library for Arduino
|
Go to the documentation of this file.
7 #include <AH/STL/array>
8 #include <AH/STL/cstddef>
9 #include <AH/STL/initializer_list>
10 #include <AH/STL/vector>
20 #include <initializer_list>
25 #if defined(ARDUINO) || defined(ARDUINO_TEST)
142 bool add(
const char *key,
const T *data,
size_t count) {
144 if (key ==
nullptr || key[0] ==
'\0')
147 if (data ==
nullptr && count != 0)
156 return append(key, data, count);
187 bool add(
const char *key,
const T &value) {
188 return add(key, &value, 1);
216 bool add(
const char *key,
const char *data) {
217 return add(key, data, strlen(data) + 1);
249 template <
class T,
size_t N>
250 bool add(
const char *key,
const T (&array)[N]) {
251 return add(key, array, N);
282 bool add(
const char *key, std::initializer_list<T> list) {
283 return add(key, list.begin(), list.size());
315 template <
class T,
size_t N>
316 bool add(
const char *key,
const std::array<T, N> &array) {
317 return add(key, array.data(), N);
348 bool add(
const char *key,
const std::vector<T> &vector) {
349 return add(key, vector.data(), vector.size());
361 #if !defined(ARDUINO) || defined(DOXYGEN)
362 void print(std::ostream &os)
const;
366 #if defined(ARDUINO) || defined(ARDUINO_TEST) || defined(DOXYGEN)
374 void print(Print &os)
const;
401 uint8_t *
writeHeader(
const char *key, uint8_t typeID,
size_t length);
406 bool append(
const char *key,
const T *data,
size_t count);
430 this->bufferwritelocation =
buffer;
431 this->bufferSize = size;
448 #define ADD_VAR(dict, var) dict.add(#var, var)
bool add(const char *key, const char *data)
Add a key-value pair to the dictionary, or update the existing value with the same key.
A class for serializing key-value/array data in a dictionary-like container that can be sent to anoth...
bool add(const char *key, std::initializer_list< T > list)
Add a key-value pair to the dictionary, or update the existing value with the same key.
void changeBuffer(uint8_t *buffer, size_t size)
Replace the buffer.
bool add(const char *key, const T *data, size_t count)
Add a key-value pair to the dictionary, or update the existing value with the same key.
bool add(const char *key, const T(&array)[N])
Add a key-value pair to the dictionary, or update the existing value with the same key.
const uint8_t * getBuffer() const
Get the buffer containing the dictionary.
KV_Builder(uint8_t *buffer, size_t bufferSize)
bool append(const char *key, const T *data, size_t count)
Append the new element to the buffer.
uint8_t * writeHeader(const char *key, uint8_t typeID, size_t length)
Write the header of a new element into the buffer, advance the write pointer, and return a pointer to...
Iterating over a dictionary generated by the KV_Builder, used for parsing and for checking if a key i...
void printPython(std::ostream &os) const
bool add(const char *key, const std::vector< T > &vector)
Add a key-value pair to the dictionary, or update the existing value with the same key.
KV_Builder with a static buffer.
bool overwrite(KV_Iterator::iterator existing, const T *data, size_t count)
Overwrite the existing element referenced by existing with the new data, if the type and size match.
uint8_t * bufferwritelocation
A pointer to the first free/unused byte in the buffer.
static iterator end()
End/sentinel iterator.
void clear()
Clear all elements of the dictionary.
KV_Iterator::iterator find(const char *key) const
Get the element with the given key.
size_t getBufferSize() const
Get the total size of the buffer.
bool add(const char *key, const std::array< T, N > &array)
Add a key-value pair to the dictionary, or update the existing value with the same key.
bool add(const char *key, const T &value)
Add a key-value pair to the dictionary, or update the existing value with the same key.
size_t getLength() const
Get the length of the used part of the buffer.
size_t maxLen
The maximum remaining length that is still free.
std::array< uint8_t, N > buffer
void print(std::ostream &os) const