Arduino KVComm
master
Key-Value pair communication library for Arduino
|
Go to the documentation of this file.
9 #include <AH/STL/array>
10 #include <AH/STL/cstddef>
11 #include <AH/STL/cstdint>
12 #include <AH/STL/iterator>
13 #include <AH/STL/vector>
62 const char *
getID()
const {
return (
const char *)
buffer + 4; }
68 explicit operator bool()
const {
return buffer !=
nullptr; }
96 void get(T &t,
size_t index = 0)
const {
98 KV_ERROR(
F(
"Trying to extract data from non-existent entry"),
105 KV_ERROR(
F(
"Index out of range"), 0x7564);
156 KV_ERROR(
F(
"Trying to extract data from non-existent entry"),
163 std::vector<T> result(size);
165 for (T &t : result) {
192 template <
class T,
size_t N>
195 KV_ERROR(
F(
"Trying to extract data from non-existent entry"),
205 std::array<T, N> result;
207 for (T &t : result) {
214 #if !defined(ARDUINO) || defined(DOXYGEN)
256 <<
getTypeID() <<
F(
", conversion requested to ")
293 explicit operator bool()
const {
return !!
kv; }
315 iterator
find(
const char *key)
const;
Class for iterating over a dictionary generated by the KV_Builder, used for parsing and for checking ...
const KV * operator->() const
iterator find(const char *key) const
Find the entry with the given key (iterates over entire dictionary).
std::vector< T > getVector() const
Get the data of the element as a vector of the given type.
Template struct for making types serializable.
std::array< T, N > getArray() const
Get the data of the element as an array of the given type.
std::input_iterator_tag iterator_category
static T readFromBuffer(const uint8_t *buffer)
bool checkType() const
Assert that the type of this entry matches the given type T.
KV_Type type definitions for fundamental types (int::_t, uint::_t, float, double, bool,...
const KV & operator*() const
constexpr static uint8_t getTypeID()
uint8_t getTypeID() const
Get the type ID of the current element.
std::string getString() const
Get the character array as an std::string.
size_t nextWord(size_t i)
Get the offset of the next 4-byte word.
const uint8_t * getData() const
Get a pointer to the data of the current element.
uint16_t getDataLength() const
Get the length of the data of the current element.
T getAs(size_t index=0) const
Get the data as the given type.
size_t remainingBufferLength
uint16_t getIDLength() const
Get the length of the identifier / key of the current element.
KV(const uint8_t *buffer)
Constructor.
iterator & operator++()
Advance the iterator.
const uint8_t * getBuffer() const
Get a pointer to the beginning of the current element.
static iterator end()
End/sentinel iterator.
iterator()
Default constructor. Used as "end" iterator (sentinel).
uint16_t getArraySize() const
Get the number of elements in the array of data.
#define KV_ERROR(msg, errc)
Throw an error.
const char * getID() const
Get the identifier / key of the current element.
bool operator!=(const iterator &other) const
Compare the iterator to the "end" iterator.
KV_Iterator(const uint8_t *buffer, size_t length)
Helpers for address manipulation used to layout dictionary entries in memory.
bool operator==(ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
Slice == Slice.
bool hasType() const
Check if the type of this element is the same as the given type.
iterator begin() const
Iterator to the first key-value entry of the dictionary.
void get(T &t, size_t index=0) const
Get the data as the given type.
constexpr static size_t getLength()