Arduino KVComm
master
Key-Value pair communication library for Arduino
|
Go to the documentation of this file.
6 #include <AH/STL/limits>
7 #include <AH/STL/memory>
21 using std::make_unique;
25 #if defined(ARDUINO) || defined(ARDUINO_TEST)
36 size_t keyLen = strlen(key);
53 size_t dataStartIndex = 4 +
nextWord(keyLen);
69 return val >= 10 ? val +
'A' - 10 : val +
'0';
73 static inline void printHex(S &os, uint8_t val) {
78 void printW(S &os,
unsigned u, uint8_t w,
char fill =
' ') {
79 auto str = make_unique<char[]>(w + 1);
81 char *begin = &str[0];
82 char *end = begin + w - 1;
84 *end-- = u % 10 +
'0';
86 }
while (u > 0 && end >= begin);
91 while (end >= begin) {
99 for (
size_t i = 0; i < dict.
getLength(); i += 4) {
102 for (uint8_t j = 0; j < 4; ++j) {
107 for (uint8_t j = 0; j < 4; ++j) {
108 char c = isprint(dict.
getBuffer()[i + j])
120 for (
size_t i = 0; i < dict.
getLength(); i += 4) {
122 for (uint8_t j = 0; j < 4; ++j) {
132 #if !defined(ARDUINO) || defined(DOXYGEN)
139 #if defined(ARDUINO) || defined(ARDUINO_TEST)
148 return dict.
find(key);
Class for iterating over a dictionary generated by the KV_Builder, used for parsing and for checking ...
iterator find(const char *key) const
Find the entry with the given key (iterates over entire dictionary).
A class for serializing key-value/array data in a dictionary-like container that can be sent to anoth...
void printPython(const KV_Builder &dict, S &os)
void printW(S &os, unsigned u, uint8_t w, char fill=' ')
const uint8_t * getBuffer() const
Get the buffer containing the dictionary.
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...
size_t nextWord(size_t i)
Get the offset of the next 4-byte word.
void printPython(std::ostream &os) const
static void printHex(S &os, uint8_t val)
uint8_t * bufferwritelocation
A pointer to the first free/unused byte in the buffer.
static char nibbleToHex(uint8_t val)
void print(const KV_Builder &dict, S &os)
size_t roundUpToWordSizeMultiple(size_t i)
Round up a size to a multiple of 4-byte words.
KV_Iterator::iterator find(const char *key) const
Get the element with the given key.
Helpers for address manipulation used to layout dictionary entries in memory.
constexpr auto max(const T &a, const U &b) -> decltype(a< b ? b :a)
Return the larger of two numbers/objects.
size_t getLength() const
Get the length of the used part of the buffer.
This file contains the KV_Builder class, a key-value pair, dictionary-like container that supports ma...
size_t maxLen
The maximum remaining length that is still free.
void print(std::ostream &os) const