|
errno_t | Open (OutputStream *stream) noexcept |
| Specifies a stream and starts generating data. More...
|
|
bool | Flush () noexcept |
| Writes data to the stream and flushes the stream. More...
|
|
errno_t | Close () noexcept |
| Closes the generator and sets it to the state immediately after it is initialized. More...
|
|
JsonStreamGenerator & | Null () noexcept |
| Outputs null . More...
|
|
JsonStreamGenerator & | Boolean (bool value) noexcept |
| Outputs true or false . More...
|
|
JsonStreamGenerator & | Int8 (int8_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Uint8 (uint8_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Int16 (int16_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Uint16 (uint16_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Int32 (int32_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Uint32 (uint32_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Int64 (int64_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Uint64 (uint64_t num) noexcept |
| Outputs an integer value. More...
|
|
JsonStreamGenerator & | Float (float num) noexcept |
| Outputs a floating-point number. More...
|
|
JsonStreamGenerator & | Double (double num) noexcept |
| Outputs a floating-point number. More...
|
|
JsonStreamGenerator & | String (const nlib_utf8_t *str) noexcept |
| Outputs a string. More...
|
|
JsonStreamGenerator & | Binary (const void *bin, size_t n) noexcept |
| Outputs binary data. Currently, only outputting msgpack is supported. More...
|
|
JsonStreamGenerator & | Ext (int8_t tp, const void *bin, size_t n) noexcept |
| Outputs extended data. More...
|
|
JsonStreamGenerator & | Timestamp (nlib_time t) noexcept |
| Outputs a timestamp. For JSON, it is output as a string. More...
|
|
JsonStreamGenerator & | Object (const MpObject &obj) noexcept |
| Outputs MpObject . More...
|
|
|
constexpr | JsonStreamGenerator () noexcept |
| Instantiates the object with default parameters (default constructor).
|
|
| ~JsonStreamGenerator () noexcept |
| Destructor.
|
|
| JsonStreamGenerator (JsonStreamGenerator &&rhs) |
| Instantiates the object (move constructor).
|
|
JsonStreamGenerator & | operator= (JsonStreamGenerator &&rhs) |
| Move assignment operator.
|
|
void | Reset () noexcept |
| Resets this object to the state immediately after the default constructor was executed.
|
|
errno_t | Init (const JsonStreamGeneratorSettings &settings) noexcept |
| Initializes by specifying the behavior option. Returns 0 if successful. More...
|
|
errno_t | Init () noexcept |
| A parameter omitted version of the above function which passes settings as the default value.
|
|
|
JsonStreamGenerator & | StartArray (size_t count) noexcept |
| Starts outputting the array. More...
|
|
JsonStreamGenerator & | EndArray () noexcept |
| Finishes the array. More...
|
|
JsonStreamGenerator & | EmptyArray () noexcept |
| Outputs an empty array. More...
|
|
JsonStreamGenerator & | Int8Array (const int8_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Uint8Array (const uint8_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Int16Array (const int16_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Uint16Array (const uint16_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Int32Array (const int32_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Uint32Array (const uint32_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Int64Array (const int64_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | Uint64Array (const uint64_t *p, size_t count) noexcept |
| Outputs an integer array. More...
|
|
JsonStreamGenerator & | FloatArray (const float *p, size_t count) noexcept |
| Outputs a single-precision floating point number array. More...
|
|
JsonStreamGenerator & | DoubleArray (const double *p, size_t count) noexcept |
| Outputs a double-precision floating point number array. More...
|
|
|
JsonStreamGenerator & | StartMap (size_t count) noexcept |
| Starts outputting the map. More...
|
|
JsonStreamGenerator & | Key (const nlib_utf8_t *key) noexcept |
| Outputs keys for the associative array. More...
|
|
JsonStreamGenerator & | EndMap () noexcept |
| Finishes the map. More...
|
|
JsonStreamGenerator & | EmptyMap () noexcept |
| Outputs an empty map. More...
|
|
|
Error | GetError () const noexcept |
| Gets an error. More...
|
|
| operator bool () const |
| Returns true if the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
|
|
|
static errno_t | Generate (size_t *written, nlib_utf8_t *str, size_t n, const MpObject &obj, const JsonStreamGeneratorSettings &settings) noexcept |
| Outputs the content of obj in JSON or msgpack. More...
|
|
static errno_t | Generate (size_t *written, nlib_utf8_t *str, size_t n, const MpObject &obj) noexcept |
| A parameter omitted version of the above function which passes settings as the default value.
|
|
template<size_t N> |
static errno_t | Generate (size_t *written, nlib_utf8_t(&str)[N], const MpObject &obj, const JsonStreamGeneratorSettings &settings) noexcept |
| A template overload of the above function.
|
|
template<size_t N> |
static errno_t | Generate (size_t *written, nlib_utf8_t(&str)[N], const MpObject &obj) noexcept |
| A template overload of the above function.
|
|
static std::pair< errno_t, size_t > | Generate (nlib_utf8_t *str, size_t n, const MpObject &obj, const JsonStreamGeneratorSettings &settings) noexcept |
| Outputs the content of obj in JSON or msgpack. More...
|
|
template<size_t N> |
static std::pair< errno_t, size_t > | Generate (nlib_utf8_t(&str)[N], const MpObject &obj, const JsonStreamGeneratorSettings &settings) noexcept |
| A template overload of the above function.
|
|
static std::pair< errno_t, size_t > | Generate (nlib_utf8_t *str, size_t n, const MpObject &obj) noexcept |
| A parameter omitted version of the above function which passes settings as the default value.
|
|
template<size_t N> |
static std::pair< errno_t, size_t > | Generate (nlib_utf8_t(&str)[N], const MpObject &obj) noexcept |
| A template overload of the above function.
|
|
The class for outputting JSON or msgpack.
- Description
- After finishing initialization, writing a method chain with the following code allow JSON or msgpack to be output.
MemoryOutputStream stream(buf);
SUCCEED_IF(gen.Init() == 0);
SUCCEED_IF(gen.Open(&stream) == 0);
gen.StartMap(3);
gen.Key("key1").String("value");
gen.Key("key2").StartArray(3).Int32(1).Int32(2).Int32(3).EndArray();
gen.Key("key3").StartArray(2).Boolean(true).Null().EndArray();
gen.EndMap();
SUCCEED_IF(gen.Close() == 0);
size_t n = stream.Pos();
SUCCEED_IF(stream.Close());
buf[n] = '\0';
It is also possible to easily output it from MpObject
by using a static member function. SUCCEED_IF(r.first == 0);
Definition at line 42 of file JsonStreamGenerator.h.