JSON generator. Converts an MpObject
to JSON and writes it to the stream.
More...
#include "nn/nlib/msgpack/JsonWriter.h"
|
static bool | Write (char *str, size_t n, const MpObject &obj, uint32_t option=0) noexcept |
| Converts obj to JSON, and writes it to str via the memory stream. More...
|
|
template<size_t n> |
static bool | Write (char(&str)[n], const MpObject &obj, uint32_t option=0) noexcept |
| Converts obj to JSON, and writes it to str via the memory stream. More...
|
|
JSON generator. Converts an MpObject
to JSON and writes it to the stream.
Definition at line 18 of file JsonWriter.h.
Defines the option values that can be passed to Write
.
Enumerator |
---|
OPTION_DEFAULT |
The default settings.
|
OPTION_RELAXED |
Relaxes the requirements where JSON must be an array or an associative array. Specify this option when you want to write a string that is not strictly JSON, such as only numbers and strings.
|
Definition at line 20 of file JsonWriter.h.
nn::nlib::msgpack::JsonWriter::Close |
( |
| ) |
|
|
noexcept |
Closes JsonWriter
.
- Returns
- Returns
true
when successful.
- Description
- Closes
JsonWriter
and detaches the base stream. The base stream will not be closed.
- The object may be reused by calling the
Init
member function again.
nn::nlib::msgpack::JsonWriter::Flush |
( |
| ) |
|
|
noexcept |
Flushes the stream that is the base stream for writing.
- Returns
- Returns
true
when successful.
nn::nlib::msgpack::JsonWriter::GetErrorValue |
( |
| ) |
const |
|
inlinenoexcept |
Gets the error that occurred.
- Return values
-
0 | No error occurred. |
EILSEQ | The MpObject is not in a format that can be converted to JSON. |
EINVAL | Error in an argument. |
EEXIST | Attempted to initialize a JsonWriter object that has already been initialized. |
EIO | An error occurred in the base stream. |
EBADF | Attempted to use an uninitialized JsonWriter . |
ENOMEM | Failed to allocate memory. |
Definition at line 29 of file JsonWriter.h.
nn::nlib::msgpack::JsonWriter::GetStream |
( |
| ) |
|
|
inlinenoexcept |
Gets the base stream specified in Init
.
- Returns
- Returns the pointer to the stream.
Definition at line 33 of file JsonWriter.h.
nn::nlib::msgpack::JsonWriter::Init |
( |
OutputStream * |
stream | ) |
|
|
noexcept |
Initializes JsonWriter
. Sets an error and returns false
when it fails.
- Parameters
-
[in] | stream | Pointer to the output stream. |
- Returns
- Returns
true
when successful.
nn::nlib::msgpack::JsonWriter::Write |
( |
const MpObject & |
obj, |
|
|
uint32_t |
option = 0 |
|
) |
| |
|
noexcept |
Converts an MpObject
to JSON and writes it to the stream.
- Parameters
-
[in] | obj | Object being converted to JSON. |
[in] | option | Option. The value synthesized by the logical disjunction of the JsonWriter::Option type value is assigned. |
- Returns
- Returns
true
when successful.
- Description
- Converts an
MpObject
to JSON and writes it to the stream. Returns true
if successful. Sets an error and returns false
when it fails.
nn::nlib::msgpack::JsonWriter::Write |
( |
char * |
str, |
|
|
size_t |
n, |
|
|
const MpObject & |
obj, |
|
|
uint32_t |
option = 0 |
|
) |
| |
|
staticnoexcept |
Converts obj to JSON, and writes it to str via the memory stream.
- Parameters
-
[out] | str | Pointer to the space where the JSON string will be stored. |
[in] | n | Size of the str parameter. |
[in] | obj | Object being converted to JSON. |
[in] | option | Option. The value synthesized by the logical disjunction of the JsonWriter::Option type value is assigned. |
- Returns
- Returns
true
when successful.
template<size_t n>
nn::nlib::msgpack::JsonWriter::Write |
( |
char(&) |
str[n], |
|
|
const MpObject & |
obj, |
|
|
uint32_t |
option = 0 |
|
) |
| |
|
inlinestaticnoexcept |
Converts obj to JSON, and writes it to str via the memory stream.
- Template Parameters
-
n | Size of the str parameter. |
- Parameters
-
[out] | str | Pointer to the space where the JSON string will be stored. |
[in] | obj | Object being converted to JSON. |
[in] | option | Option. The value synthesized by the logical disjunction of the JsonWriter::Option type value is assigned. |
- Returns
- Returns
true
when successful.
Definition at line 38 of file JsonWriter.h.
The documentation for this class was generated from the following files: