nlib
nn::nlib::msgpack::JsonWriter Class Referencefinal

JSON generator. Converts an MpObject to JSON and writes it to the stream. More...

#include "nn/nlib/msgpack/JsonWriter.h"

Public Types

enum  Option {
  OPTION_DEFAULT = 0x00000000,
  OPTION_RELAXED = 0x00000001
}
 Defines the option values that can be passed to Write. More...
 

Public Member Functions

bool Flush () noexcept
 Flushes the stream that is the base stream for writing. More...
 
bool Write (const MpObject &obj, uint32_t option=0) noexcept
 Converts an MpObject to JSON and writes it to the stream. More...
 
OutputStreamGetStream () noexcept
 Gets the base stream specified in Init. More...
 
Basic Member Functions
 JsonWriter () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonWriter () noexcept
 Destructor.
 
Initialization and Finalization
bool Init (OutputStream *stream) noexcept
 Initializes JsonWriter. Sets an error and returns false when it fails. More...
 
bool Close () noexcept
 Closes JsonWriter. More...
 
Error Checking
errno_t GetErrorValue () const noexcept
 Gets the error that occurred. More...
 
 operator bool () const
 Returns true if an error has not occurred.
 

Static Public Member Functions

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...
 

Detailed Description

JSON generator. Converts an MpObject to JSON and writes it to the stream.

Definition at line 18 of file JsonWriter.h.

Member Enumeration Documentation

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.

Member Function Documentation

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
0No error occurred.
EILSEQThe MpObject is not in a format that can be converted to JSON.
EINVALError in an argument.
EEXISTAttempted to initialize a JsonWriter object that has already been initialized.
EIOAn error occurred in the base stream.
EBADFAttempted to use an uninitialized JsonWriter.
ENOMEMFailed 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]streamPointer 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]objObject being converted to JSON.
[in]optionOption. 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]strPointer to the space where the JSON string will be stored.
[in]nSize of the str parameter.
[in]objObject being converted to JSON.
[in]optionOption. 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
nSize of the str parameter.
Parameters
[out]strPointer to the space where the JSON string will be stored.
[in]objObject being converted to JSON.
[in]optionOption. 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: