16 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMGENERATOR_H_ 17 #define INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMGENERATOR_H_ 20 #include "nn/nlib/Swap.h" 23 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 24 #undef NLIB_VIS_PUBLIC 25 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 37 : msgpack(false), pretty_print(false),
38 omit_utf8_checking(false), strict(false) {}
47 kErrorEndArrayRequired,
48 kErrorEndArrayForbidden,
50 kErrorEndMapForbidden,
54 kErrorArrayOrMapRequired,
56 kErrorBinaryNotAvailable,
57 kErrorExtNotAvailable,
60 ERROR_KEY_REQUIRED = kErrorKeyRequired,
61 ERROR_KEY_FORBIDDEN = kErrorKeyForbidden,
62 ERROR_ENDARRAY_REQUIRED = kErrorEndArrayRequired,
63 ERROR_ENDARRAY_FORBIDDEN = kErrorEndArrayForbidden,
64 ERROR_ENDMAP_REQUIRED = kErrorEndMapRequired,
65 ERROR_ENDMAP_FORBIDDEN = kErrorEndMapForbidden,
66 ERROR_STRING_UTF8 = kErrorStringUtf8,
67 ERROR_STREAM = kErrorStream,
68 ERROR_ENOMEM = kErrorOutOfMemory,
69 ERROR_ARRAY_OR_MAP_REQUIRED = kErrorArrayOrMapRequired,
70 ERROR_DOCUMENT_END = kErrorDocumentEnd,
71 ERROR_BINARY_NOT_AVAILABLE = kErrorBinaryNotAvailable,
72 ERROR_EXT_NOT_AVAILABLE = kErrorExtNotAvailable,
73 ERROR_EINVAL = kErrorInvalidParam
83 return Generate(written, str, n, obj, settings);
88 return Generate(written, str, N, obj, settings);
94 return Generate(written, str, N, obj, settings);
97 static std::pair<errno_t, size_t>
100 std::pair<errno_t, size_t> rval;
101 rval.first = Generate(&rval.second, str, n, obj, settings);
105 static std::pair<errno_t, size_t>
108 return Generate(&str[0], N, obj, settings);
110 static std::pair<errno_t, size_t>
113 return Generate(str, n, obj, settings);
116 static std::pair<errno_t, size_t>
119 return Generate(&str[0], N, obj, settings);
127 swap(prv_, rhs.prv_);
128 swap(error_, rhs.error_);
134 return Init(settings);
180 Error
GetError() const NLIB_NOEXCEPT {
return error_; }
195 struct JsonStreamGeneratorPrivate;
196 JsonStreamGeneratorPrivate* prv_;
203 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonStreamGenerator)
204 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 205 #undef NLIB_VIS_PUBLIC 206 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 209 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMGENERATOR_H_ errno_t Init() noexcept
Initializes the parser using the default settings.
static errno_t Generate(size_t *written, nlib_utf8_t(&str)[N], const MpObject &obj, const JsonStreamGeneratorSettings &settings) noexcept
Runs Generate(written, str, N, obj, settings).
bool strict
If true, generates an error if the first output is not an array or map.
static errno_t Generate(size_t *written, nlib_utf8_t(&str)[N], const MpObject &obj) noexcept
Runs Generate(written, str, N, obj, settings) with the default JsonStreamGeneratorSettings settings s...
JsonStreamGenerator & EmptyArray() noexcept
Outputs an empty array.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
JsonStreamGenerator & EndArray() noexcept
Finishes the array.
Error GetError() const noexcept
Gets an error.
constexpr JsonStreamGenerator() noexcept
Instantiates the object with default parameters (default constructor).
bool omit_utf8_checking
If true, checking if the string is UTF-8 is skipped when outputting the string.
Object created when MessagePack or JSON is read.
bool msgpack
If false, JsonStreamGenerator outputs JSON; if true, it outputs msgpack.
Object created when MessagePack, JSON, or CSV is read.
constexpr JsonStreamGeneratorSettings() noexcept
Instantiates the object with default parameters (default constructor). Sets each data member to the d...
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
~JsonStreamGenerator() noexcept
Destructor.
static errno_t Generate(size_t *written, nlib_utf8_t *str, size_t n, const MpObject &obj) noexcept
Runs Generate(written, str, n, obj, settings) with the default JsonStreamGeneratorSettings settings s...
bool pretty_print
If true, outputs formatted JSON when outputting JSON.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Data structure used to store the JsonStreamGenerator settings parameters.
JsonStreamGenerator & EndMap() noexcept
Finishes the map.
JsonStreamGenerator & EmptyMap() noexcept
Outputs an empty map.
Class for outputting JSON or msgpack.
The base class for output streams. This class cannot be instantiated.