JsonParserGeneratorRK
|
Class used internally for writing to strings. More...
#include <JsonParserGeneratorRK.h>
Public Member Functions | |
JsonParserString (String *str) | |
Construct a JsonParserString wrapping a Wiring String. More... | |
JsonParserString (char *buf, size_t bufLen) | |
Construct a JsonParserString wrapping a buffer and length. More... | |
void | append (char ch) |
Append a single char to the underlying string. More... | |
void | append (const char *str, size_t len) |
Append a buffer and length to the underlying string. More... | |
size_t | getLength () const |
Get the length of the string. More... | |
Protected Attributes | |
String * | str |
When writing to a String, the String object. | |
char * | buf |
When writing to a buffer, the pointer to the buffer. Not used for String. | |
size_t | bufLen |
When writing to a buffer, the length of the buffer in bytes. Not used for String. | |
size_t | length |
The current offset being written to. | |
Class used internally for writing to strings.
This is a wrapper around either String (the Wiring version) or a buffer and length. This allows writing to a static buffer with no dynamic memory allocation at all.
One of the things about String is that while you can pre-allocate reserve space for data, you can't get access to the internal length field, so you can't write to raw bytes then resize it to the correct size. This wrapper is that allows appending to either a String or buffer to get around this limitation of String.
You can also use it for sizing only by passing NULL for buf.
JsonParserString::JsonParserString | ( | String * | str | ) |
Construct a JsonParserString wrapping a Wiring String.
str | A pointer Wiring String object to write to. |
JsonParserString::JsonParserString | ( | char * | buf, |
size_t | bufLen | ||
) |
Construct a JsonParserString wrapping a buffer and length.
buf | A pointer to a buffer |
bufLen | The length of the buffer in bytes |
void JsonParserString::append | ( | char | ch | ) |
Append a single char to the underlying string.
ch | The char to append. |
void JsonParserString::append | ( | const char * | str, |
size_t | len | ||
) |
Append a buffer and length to the underlying string.
str | A pointer to the character to add. Does not need to be null-terminated. |
len | Length of the string to append in bytes. |
|
inline |
Get the length of the string.
For buffer and bufLenb, the maximum string length will be bufLen - 1 to leave room for the null terminator.