16 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMGENERATOR_H_ 17 #define INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMGENERATOR_H_ 19 #include "nn/nlib/Swap.h" 22 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 23 #undef NLIB_VIS_PUBLIC 24 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 36 : msgpack(false), pretty_print(false),
37 omit_utf8_checking(false), strict(false) {}
46 kErrorEndArrayRequired,
47 kErrorEndArrayForbidden,
49 kErrorEndMapForbidden,
53 kErrorArrayOrMapRequired,
55 kErrorBinaryNotAvailable,
56 kErrorExtNotAvailable,
59 ERROR_KEY_REQUIRED = kErrorKeyRequired,
60 ERROR_KEY_FORBIDDEN = kErrorKeyForbidden,
61 ERROR_ENDARRAY_REQUIRED = kErrorEndArrayRequired,
62 ERROR_ENDARRAY_FORBIDDEN = kErrorEndArrayForbidden,
63 ERROR_ENDMAP_REQUIRED = kErrorEndMapRequired,
64 ERROR_ENDMAP_FORBIDDEN = kErrorEndMapForbidden,
65 ERROR_STRING_UTF8 = kErrorStringUtf8,
66 ERROR_STREAM = kErrorStream,
67 ERROR_ENOMEM = kErrorOutOfMemory,
68 ERROR_ARRAY_OR_MAP_REQUIRED = kErrorArrayOrMapRequired,
69 ERROR_DOCUMENT_END = kErrorDocumentEnd,
70 ERROR_BINARY_NOT_AVAILABLE = kErrorBinaryNotAvailable,
71 ERROR_EXT_NOT_AVAILABLE = kErrorExtNotAvailable,
72 ERROR_EINVAL = kErrorInvalidParam
82 return Generate(written, str, n, obj, settings);
87 return Generate(written, str, N, obj, settings);
93 return Generate(written, str, N, obj, settings);
102 return Init(settings);
130 template<
class STDSTRING>
132 return String(str.c_str());
146 Error
GetError() const NLIB_NOEXCEPT {
return error_; }
150 swap(prv_, rhs.prv_);
151 swap(error_, rhs.error_);
166 struct JsonStreamGeneratorPrivate;
167 JsonStreamGeneratorPrivate* prv_;
174 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonStreamGenerator)
175 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 176 #undef NLIB_VIS_PUBLIC 177 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 180 #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.
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.
JsonStreamGenerator & String(const STDSTRING &str) noexcept
Outputs a string.
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.
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.