Arduino KVComm  master
Key-Value pair communication library for Arduino
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
KV_Iterator::KV Class Reference

#include <KVComm/KV_Iterator.hpp>

Collaboration diagram for KV_Iterator::KV:

Public Member Functions

 KV (const uint8_t *buffer)
 Constructor. More...
 
uint8_t getTypeID () const
 Get the type ID of the current element. More...
 
uint16_t getIDLength () const
 Get the length of the identifier / key of the current element. More...
 
uint16_t getDataLength () const
 Get the length of the data of the current element. More...
 
const uint8_t * getBuffer () const
 Get a pointer to the beginning of the current element. More...
 
const char * getID () const
 Get the identifier / key of the current element. More...
 
const uint8_t * getData () const
 Get a pointer to the data of the current element. More...
 
 operator bool () const
 Check if the key-value pair is valid. More...
 
template<class T >
uint16_t getArraySize () const
 Get the number of elements in the array of data. More...
 
template<class T >
void get (T &t, size_t index=0) const
 Get the data as the given type. More...
 
template<class T >
getAs (size_t index=0) const
 Get the data as the given type. More...
 
template<class T >
std::vector< T > getVector () const
 Get the data of the element as a vector of the given type. More...
 
template<class T , size_t N>
std::array< T, N > getArray () const
 Get the data of the element as an array of the given type. More...
 
std::string getString () const
 Get the character array as an std::string. More...
 
template<class T >
bool hasType () const
 Check if the type of this element is the same as the given type. More...
 

Protected Member Functions

template<class T >
bool checkType () const
 Assert that the type of this entry matches the given type T. More...
 

Private Attributes

const uint8_t * buffer
 

Detailed Description

Examples
KVComm-Receive.ino.

Definition at line 47 of file KV_Iterator.hpp.

Constructor & Destructor Documentation

◆ KV()

KV ( const uint8_t *  buffer)
inline

Constructor.

Definition at line 50 of file KV_Iterator.hpp.

Member Function Documentation

◆ getTypeID()

uint8_t getTypeID ( ) const
inline

Get the type ID of the current element.

Examples
KVComm-Receive.ino.

Definition at line 52 of file KV_Iterator.hpp.

◆ getIDLength()

uint16_t getIDLength ( ) const
inline

Get the length of the identifier / key of the current element.

Definition at line 54 of file KV_Iterator.hpp.

◆ getDataLength()

uint16_t getDataLength ( ) const
inline

Get the length of the data of the current element.

Definition at line 56 of file KV_Iterator.hpp.

◆ getBuffer()

const uint8_t* getBuffer ( ) const
inline

Get a pointer to the beginning of the current element.

Definition at line 60 of file KV_Iterator.hpp.

◆ getID()

const char* getID ( ) const
inline

Get the identifier / key of the current element.

Examples
KVComm-Receive.ino.

Definition at line 62 of file KV_Iterator.hpp.

◆ getData()

const uint8_t* getData ( ) const
inline

Get a pointer to the data of the current element.

Definition at line 64 of file KV_Iterator.hpp.

◆ operator bool()

operator bool ( ) const
inlineexplicit

Check if the key-value pair is valid.

Definition at line 68 of file KV_Iterator.hpp.

◆ getArraySize()

uint16_t getArraySize ( ) const
inline

Get the number of elements in the array of data.

Examples
KVComm-Receive.ino.

Definition at line 72 of file KV_Iterator.hpp.

◆ get()

void get ( T &  t,
size_t  index = 0 
) const
inline

Get the data as the given type.

Template Parameters
TThe type of value to read.
Parameters
[out]tThe value is read from the dictionary into this variable.
[in]indexThe index of the element of the array to read (if the value is an array).
Exceptions
0x7566Trying to extract data from non-existent entry.
0x7563Type mismatch: The dynamic type ID doesn't match the type ID of T.
0x7564Index out of range.

Definition at line 96 of file KV_Iterator.hpp.

◆ getAs()

T getAs ( size_t  index = 0) const
inline

Get the data as the given type.

Template Parameters
TThe type of value to read.
Parameters
indexThe index of the element of the array to read (if the value is an array).
Returns
The requested element of the value from this key-value pair, casted to the given type T.
Exceptions
0x7566Trying to extract data from non-existent entry.
0x7563Type mismatch: The dynamic type ID doesn't match the type ID of T.
0x7564Index out of range.
Examples
KVComm-Receive.ino.

Definition at line 132 of file KV_Iterator.hpp.

◆ getVector()

std::vector<T> getVector ( ) const
inline

Get the data of the element as a vector of the given type.

Template Parameters
TThe type of the data. This must be the same as the dynamic type of the data.
Returns
A vector containing the data of the element, converted to the correct type.
Exceptions
0x7566Trying to extract data from non-existent entry.
0x7563Type mismatch: The dynamic type ID doesn't match the type ID of T.

Definition at line 154 of file KV_Iterator.hpp.

◆ getArray()

std::array<T, N> getArray ( ) const
inline

Get the data of the element as an array of the given type.

Template Parameters
TThe type of the data. This must be the same as the dynamic type of the data.
NThe number of elements in the array. This must be the same as the length of the data.
Returns
An array containing the data of the element, converted to the correct type.
Exceptions
0x7566Trying to extract data from non-existent entry.
0x7563Type mismatch: The dynamic type ID doesn't match the type ID of T.
0x7565Incorrect length: The specified array size N doesn't match the actual dynamic size of the element.

Definition at line 193 of file KV_Iterator.hpp.

◆ getString()

std::string getString ( ) const

Get the character array as an std::string.

Returns
The character array as a string.
Note
Returns an Arduino String instead of an std::string on Arduino.
Exceptions
0x7566Trying to extract data from non-existent entry.
0x7563Type mismatch: The dynamic type ID doesn't match the type ID of char.
Examples
KVComm-Receive.ino.

Definition at line 57 of file KV_Iterator.cpp.

◆ hasType()

bool hasType ( ) const
inline

Check if the type of this element is the same as the given type.

Template Parameters
TThe type to compare to the type of this element.
Return values
trueThe types are the same.
falseOtherwise.

Definition at line 246 of file KV_Iterator.hpp.

◆ checkType()

bool checkType ( ) const
inlineprotected

Assert that the type of this entry matches the given type T.

Definition at line 253 of file KV_Iterator.hpp.

Member Data Documentation

◆ buffer

const uint8_t* buffer
private

Definition at line 265 of file KV_Iterator.hpp.


The documentation for this class was generated from the following files: