Base class for managing a static or dynamic buffer, used by both JsonParser and JsonWriter.
More...
#include <JsonParserGeneratorRK.h>
|
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.
|
|
Base class for managing a static or dynamic buffer, used by both JsonParser and JsonWriter.
◆ JsonBuffer()
JsonBuffer::JsonBuffer |
( |
char * |
buffer, |
|
|
size_t |
bufferLen |
|
) |
| |
Construct a JsonBuffer with an external buffer of a given size.
- Parameters
-
buffer | Pointer to the buffer |
bufferLen | The length of the buffer |
This buffer will not be deleted when the object is destructed.
◆ addData()
bool JsonBuffer::addData |
( |
const char * |
data, |
|
|
size_t |
dataLen |
|
) |
| |
Add a string to the end of the buffer.
- Parameters
-
data | Pointer to the string bytes. Does not need to be null-terminated |
dataLen | Length of the data in bytes. For UTF-8, this is the number of bytes, not characters! |
◆ addString()
bool JsonBuffer::addString |
( |
const char * |
data | ) |
|
|
inline |
Add a c-string to the end of the buffer.
- Parameters
-
data | Pointer to a c-string (null terminated). |
◆ allocate()
bool JsonBuffer::allocate |
( |
size_t |
len | ) |
|
Allocate the buffer using malloc/realloc.
- Parameters
-
len | The length of the buffer in bytes |
- Returns
- true if the allocation/reallocation was successful or false if there was not enough free memory.
There's also a version that takes a pointer and length to use a static buffer instead of a dynamically allocated one.
◆ clear()
void JsonBuffer::clear |
( |
| ) |
|
Clears the current buffer for writing.
This only sets the offset to 0, it does not clear the bytes.
◆ getBuffer()
char* JsonBuffer::getBuffer |
( |
| ) |
const |
|
inline |
Gets a pointer to the internal buffer.
Note: The internal buffer is not null-terminated!
◆ getBufferLen()
size_t JsonBuffer::getBufferLen |
( |
| ) |
const |
|
inline |
Gets the current length of the buffer.
The buffer length is either the bufferLen passed to the constructor that takes a buffer and bufferLen or the length allocated using allocate(len).
◆ setBuffer()
void JsonBuffer::setBuffer |
( |
char * |
buffer, |
|
|
size_t |
bufferLen |
|
) |
| |
Sets the buffers to the specified buffer and length.
- Parameters
-
buffer | Pointer to the buffer |
bufferLen | The length of the buffer |
This buffer will not be deleted when the object is destructed.
The documentation for this class was generated from the following files: