JsonParserGeneratorRK
Public Member Functions
JsonParserStatic< BUFFER_SIZE, MAX_TOKENS > Class Template Reference

Creates a JsonParser with a static buffer. More...

#include <JsonParserGeneratorRK.h>

Inheritance diagram for JsonParserStatic< BUFFER_SIZE, MAX_TOKENS >:
JsonParser JsonBuffer

Public Member Functions

 JsonParserStatic ()
 Construct a JsonParser using a static buffer and static maximum number of tokens.
 
- Public Member Functions inherited from JsonParser
 JsonParser ()
 Construct a parser object. More...
 
virtual ~JsonParser ()
 Destroy a parser object. More...
 
 JsonParser (char *buffer, size_t bufferLen, JsonParserGeneratorRK::jsmntok_t *tokens, size_t maxTokens)
 Static buffers constructor.
 
bool allocateTokens (size_t maxTokens)
 Preallocates a specific number of tokens. More...
 
bool parse ()
 Parses the data you have added using addData() or addString(). More...
 
JsonReference getReference () const
 Get a JsonReference object. This is used for fluent-style access to the data.
 
const JsonParserGeneratorRK::jsmntok_tgetOuterObject () const
 Gets the outer JSON object token. More...
 
const JsonParserGeneratorRK::jsmntok_tgetOuterArray () const
 Gets the outer JSON array token. More...
 
const JsonParserGeneratorRK::jsmntok_tgetOuterToken () const
 Gets the outer JSON object or array token. More...
 
size_t getArraySize (const JsonParserGeneratorRK::jsmntok_t *arrayContainer) const
 Given a token for an JSON array in arrayContainer, gets the number of elements in the array. More...
 
template<class T >
bool getValueByKey (const JsonParserGeneratorRK::jsmntok_t *container, const char *name, T &result) const
 Given an object token in container, gets the value with the specified key name. More...
 
template<class T >
bool getOuterValueByKey (const char *name, T &result) const
 Gets the value with the specified key name out of the outer object. More...
 
template<class T >
bool getKeyValueByIndex (const JsonParserGeneratorRK::jsmntok_t *container, size_t index, String &key, T &result) const
 Gets the key/value pair of an object by index. More...
 
template<class T >
bool getOuterKeyValueByIndex (size_t index, String &key, T &result) const
 Gets the key/value pair of the outer object by index (0 = first, 1 = second, ...) More...
 
template<class T >
bool getValueByIndex (const JsonParserGeneratorRK::jsmntok_t *arrayContainer, size_t index, T &result) const
 Given an array token in arrayContainer, gets the value with the specified index. More...
 
template<class T >
bool getValueByColRow (const JsonParserGeneratorRK::jsmntok_t *arrayContainer, size_t col, size_t row, T &result) const
 This method is used to extract data from a 2-dimensional JSON array, an array of arrays of values. More...
 
bool getValueTokenByKey (const JsonParserGeneratorRK::jsmntok_t *container, const char *key, const JsonParserGeneratorRK::jsmntok_t *&value) const
 Given an object token in container, gets the token value with the specified key name. More...
 
bool getValueTokenByIndex (const JsonParserGeneratorRK::jsmntok_t *container, size_t desiredIndex, const JsonParserGeneratorRK::jsmntok_t *&value) const
 Given an array token in container, gets the token value with the specified index. More...
 
bool getValueTokenByColRow (const JsonParserGeneratorRK::jsmntok_t *container, size_t col, size_t row, const JsonParserGeneratorRK::jsmntok_t *&value) const
 This method is used to extract data from a 2-dimensional JSON array, an array of arrays of values. More...
 
const JsonParserGeneratorRK::jsmntok_tgetTokenByIndex (const JsonParserGeneratorRK::jsmntok_t *container, size_t desiredIndex) const
 Given a containing object, finds the nth token in the object. Internal use only. More...
 
bool getKeyValueTokenByIndex (const JsonParserGeneratorRK::jsmntok_t *container, const JsonParserGeneratorRK::jsmntok_t *&key, const JsonParserGeneratorRK::jsmntok_t *&value, size_t index) const
 Given a JSON object in container, gets the key/value pair specified by index. Internal use only. More...
 
bool skipObject (const JsonParserGeneratorRK::jsmntok_t *container, const JsonParserGeneratorRK::jsmntok_t *&obj) const
 Used internally to skip over the token in obj. More...
 
void copyTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, char *dst, size_t dstLen) const
 Copies the value of the token into a buffer, making it a null-terminated cstring. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, bool &result) const
 Gets a bool (boolean) value. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, int &result) const
 Gets an integer value. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, unsigned long &result) const
 Gets an unsigned long value. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, float &result) const
 Gets a float (single precision floating point) value. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, double &result) const
 Gets a double (double precision floating point) value. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, String &result) const
 Gets a String value into a Wiring String object. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, char *str, size_t &strLen) const
 Gets a string as a c-string into the specified buffer. More...
 
bool getTokenValue (const JsonParserGeneratorRK::jsmntok_t *token, JsonParserString &str) const
 Gets a string as a JsonParserString object. More...
 
bool getTokenJsonString (const JsonParserGeneratorRK::jsmntok_t *token, String &result) const
 Converts a token (object, array, string, or primitive) back into JSON in a Wiring String. More...
 
bool getTokenJsonString (const JsonParserGeneratorRK::jsmntok_t *token, char *str, size_t &strLen) const
 Converts a token (object, array, string, or primitive) back into JSON in a buffer. More...
 
bool getTokenJsonString (const JsonParserGeneratorRK::jsmntok_t *token, JsonParserString &str) const
 Gets a token as a JSON string. More...
 
JsonParserGeneratorRK::jsmntok_tgetTokens ()
 Used internally in the test suite for printing the token list.
 
JsonParserGeneratorRK::jsmntok_tgetTokensEnd ()
 Used internally in the test suite for printing the token list.
 
size_t getMaxTokens () const
 Used internally in the test suite for printing the token list.
 
- Public Member Functions inherited from JsonBuffer
 JsonBuffer ()
 Construct a JsonBuffer object with no external buffer specified.
 
virtual ~JsonBuffer ()
 Destructor. Destroying the object does not delete any underlying buffer!
 
 JsonBuffer (char *buffer, size_t bufferLen)
 Construct a JsonBuffer with an external buffer of a given size. More...
 
void setBuffer (char *buffer, size_t bufferLen)
 Sets the buffers to the specified buffer and length. More...
 
bool allocate (size_t len)
 Allocate the buffer using malloc/realloc. More...
 
bool addString (const char *data)
 Add a c-string to the end of the buffer. More...
 
bool addData (const char *data, size_t dataLen)
 Add a string to the end of the buffer. More...
 
char * getBuffer () const
 Gets a pointer to the internal buffer. More...
 
size_t getOffset () const
 Gets the current offset for writing.
 
void setOffset (size_t offset)
 swets the current offset for writing
 
size_t getBufferLen () const
 Gets the current length of the buffer. More...
 
void clear ()
 Clears the current buffer for writing. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from JsonParser
static void appendUtf8 (uint16_t unicode, JsonParserString &str)
 Given a Unicode UTF-16 code point, converts it to UTF-8 and appends it to str.
 
- Protected Attributes inherited from JsonParser
JsonParserGeneratorRK::jsmntok_ttokens
 Array of tokens after parsing.
 
JsonParserGeneratorRK::jsmntok_ttokensEnd
 Pointer into tokens, points after last used token.
 
size_t maxTokens
 Number of tokens that can be stored in tokens.
 
JsonParserGeneratorRK::jsmn_parser parser
 The JSMN parser object.
 
- Protected Attributes inherited from JsonBuffer
char * buffer
 The buffer to to read from or write to. This is not null-terminated.
 
size_t bufferLen
 The length of the buffer in bytes,.
 
size_t offset
 The read or write offset.
 
bool staticBuffers
 True if the buffers were passed in and should not freed or reallocated.
 

Detailed Description

template<size_t BUFFER_SIZE, size_t MAX_TOKENS>
class JsonParserStatic< BUFFER_SIZE, MAX_TOKENS >

Creates a JsonParser with a static buffer.

You normally use this when you're creating a parser as a global variable. For small data (under around 256 bytes so) you can also allocate one on the stack.

Parameters
BUFFER_SIZEThe maximum size of the data to be parsed, in bytes. If you are parsing a webhook response split into parts, this is the total size of all parts.
MAX_TOKENSThe maximum number of tokens you expect. Each object has a token and two for each key/value pair. Each array is a token and one for each element in the array.

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