3 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_ 4 #define INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_ 11 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 12 #undef NLIB_VIS_PUBLIC 13 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 33 max_array_size(8192), max_map_size(256), token_buffer_size(2048), max_depth(7),
34 format(FORMAT_ADAPTIVE), strict(false) {}
95 return Parse(parser, obj,
false);
102 return Parse(obj, data, n, settings);
107 if (settings.
format == JsonStreamParserSettings::FORMAT_JSON) {
108 return Parse(obj, str, n, settings);
111 settings_.
format = JsonStreamParserSettings::FORMAT_JSON;
112 return Parse(obj, str, n, settings_);
117 return Parse(obj, str, settings);
132 return this->Init(settings);
153 struct JsonStreamParserPrivate;
154 JsonStreamParserPrivate* prv_;
160 NLIB_EINVAL_IFNULL(number);
161 switch (token.event) {
162 case EVENT_NUMBER_INT32:
163 *number = token.number.i32;
165 case EVENT_NUMBER_UINT32:
166 *number =
static_cast<int32_t
>(token.number.u32);
167 if (token.number.u32 > INT32_MAX)
return ERANGE;
169 case EVENT_NUMBER_INT64:
170 *number =
static_cast<int32_t
>(token.number.i64);
171 if (token.number.i64 > INT32_MAX ||
172 token.number.i64 < INT32_MIN)
return ERANGE;
174 case EVENT_NUMBER_UINT64:
175 *number =
static_cast<int32_t
>(token.number.u64);
176 if (token.number.u64 > INT32_MAX)
return ERANGE;
178 case EVENT_NUMBER_FLOAT:
179 *number =
static_cast<int32_t
>(token.number.f32);
180 if (token.number.f32 > static_cast<float>(INT32_MAX) ||
181 token.number.f32 <
static_cast<float>(INT32_MIN))
184 case EVENT_NUMBER_DOUBLE:
185 *number =
static_cast<int32_t
>(token.number.f64);
186 if (token.number.f64 > static_cast<double>(INT32_MAX) ||
187 token.number.f64 <
static_cast<double>(INT32_MIN))
197 NLIB_EINVAL_IFNULL(number);
198 switch (token.event) {
199 case EVENT_NUMBER_INT32:
200 *number =
static_cast<uint32_t
>(token.number.i32);
201 if (token.number.i32 < 0)
return ERANGE;
203 case EVENT_NUMBER_UINT32:
204 *number = token.number.u32;
206 case EVENT_NUMBER_INT64:
207 *number =
static_cast<uint32_t
>(token.number.i64);
208 if (token.number.i64 > UINT32_MAX ||
209 token.number.i64 < 0)
return ERANGE;
211 case EVENT_NUMBER_UINT64:
212 *number =
static_cast<uint32_t
>(token.number.u64);
213 if (token.number.u64 > UINT32_MAX)
return ERANGE;
215 case EVENT_NUMBER_FLOAT:
216 *number =
static_cast<uint32_t
>(token.number.f32);
217 if (token.number.f32 > static_cast<float>(UINT32_MAX) ||
218 token.number.f32 < 0.f)
221 case EVENT_NUMBER_DOUBLE:
222 *number =
static_cast<uint32_t
>(token.number.f64);
223 if (token.number.f64 > static_cast<double>(UINT32_MAX) ||
224 token.number.f64 < 0.0)
234 NLIB_EINVAL_IFNULL(number);
235 switch (token.event) {
236 case JsonStreamParser::EVENT_NUMBER_INT32:
237 *number = token.number.i32;
239 case JsonStreamParser::EVENT_NUMBER_UINT32:
240 *number =
static_cast<int64_t
>(token.number.u32);
242 case JsonStreamParser::EVENT_NUMBER_INT64:
243 *number = token.number.i64;
245 case JsonStreamParser::EVENT_NUMBER_UINT64:
246 *number =
static_cast<int64_t
>(token.number.u64);
247 if (token.number.u64 > INT64_MAX)
return ERANGE;
249 case EVENT_NUMBER_FLOAT:
250 *number =
static_cast<int64_t
>(token.number.f32);
251 if (token.number.f32 > static_cast<float>(INT64_MAX) ||
252 token.number.f32 <
static_cast<float>(INT64_MIN))
255 case EVENT_NUMBER_DOUBLE:
256 *number =
static_cast<int64_t
>(token.number.f64);
257 if (token.number.f64 > static_cast<double>(INT64_MAX) ||
258 token.number.f64 <
static_cast<double>(INT64_MIN))
268 NLIB_EINVAL_IFNULL(number);
269 switch (token.event) {
270 case EVENT_NUMBER_INT32:
271 *number =
static_cast<uint64_t
>(token.number.i32);
272 if (token.number.i32 < 0)
return ERANGE;
274 case EVENT_NUMBER_UINT32:
275 *number = token.number.u32;
277 case EVENT_NUMBER_INT64:
278 *number =
static_cast<uint64_t
>(token.number.i64);
279 if (token.number.i64 < 0)
return ERANGE;
281 case EVENT_NUMBER_UINT64:
282 *number = token.number.u64;
284 case EVENT_NUMBER_FLOAT:
285 *number =
static_cast<uint64_t
>(token.number.f32);
286 if (token.number.f32 > static_cast<float>(UINT64_MAX) ||
287 token.number.f32 < 0.f)
290 case EVENT_NUMBER_DOUBLE:
291 *number =
static_cast<uint64_t
>(token.number.f64);
292 if (token.number.f64 > static_cast<double>(UINT64_MAX) ||
293 token.number.f64 < 0.0)
303 NLIB_EINVAL_IFNULL(number);
304 switch (token.event) {
305 case EVENT_NUMBER_INT32:
306 *number =
static_cast<float>(token.number.i32);
307 if (token.number.i32 > 16777215 || token.number.i32 < -16777215)
310 case EVENT_NUMBER_UINT32:
311 *number =
static_cast<float>(token.number.u32);
312 if (token.number.u32 > 16777215)
315 case EVENT_NUMBER_INT64:
316 *number =
static_cast<float>(token.number.i64);
317 if (token.number.i64 > 16777215 || token.number.i64 < -16777215)
320 case EVENT_NUMBER_UINT64:
321 *number =
static_cast<float>(token.number.u64);
322 if (token.number.u64 > 16777215)
325 case EVENT_NUMBER_FLOAT:
326 *number = token.number.f32;
328 case EVENT_NUMBER_DOUBLE:
329 *number =
static_cast<float>(token.number.f32);
330 if (token.number.f64 < FLT_MIN ||
331 token.number.f64 > FLT_MAX)
342 NLIB_EINVAL_IFNULL(number);
343 switch (token.event) {
344 case EVENT_NUMBER_INT32:
345 *number =
static_cast<double>(token.number.i32);
347 case EVENT_NUMBER_UINT32:
348 *number =
static_cast<double>(token.number.u32);
350 case EVENT_NUMBER_INT64:
351 *number =
static_cast<double>(token.number.i64);
352 if (token.number.i64 > 9007199254740991LL ||
353 token.number.i64 < -9007199254740991LL)
356 case EVENT_NUMBER_UINT64:
357 *number =
static_cast<double>(token.number.u64);
358 if (token.number.u64 > 9007199254740991ULL)
361 case EVENT_NUMBER_FLOAT:
362 *number = token.number.f32;
364 case EVENT_NUMBER_DOUBLE:
365 *number = token.number.f64;
376 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 377 #undef NLIB_VIS_PUBLIC 378 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 381 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_ size_t token_buffer_size
Specifies the size of the buffer to store tokens. The default is 2048 and the minimum value is 512...
#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...
An int32_t type integer has been read.
bool strict
If a value other than 0 is set, a stricter error check is performed. The default is 0...
constexpr JsonStreamParserSettings() noexcept
Instantiates the object with default parameters (default constructor). Sets each data member to the d...
An int64_t type integer has been read.
char * buf
Stores strings or binary data.
Binary data has been read (msgpack only).
UniquePtr owns the pointer, and when it goes out of scope, the pointer is released by the destructor ...
Defines that class that is corresponding to std::unique_ptr.
static errno_t Parse(UniquePtr< MpObject > &obj, const void *data, size_t n) noexcept
Runs Parse(obj, data, n, settings) with the default JsonStreamParserSettings settings specified...
Extended data has been read (msgpack only).
Event event
The event returned by Next().
A string other than an associative array key has been read.
A uint64_t type integer has been read.
A double type floating-point number has been read.
Data structure used to store the JsonStreamParser settings parameters.
The class to parse JSON or msgpack in a pull manner.
The class for reading text from streams.
Event
The type used by JsonStreamParser::Next() and Token, and the event that corresponds to the data read ...
Object created when MessagePack, JSON, or CSV is read.
size_t max_map_size
Specifies the maximum associative array size. The default is 256 and the minimum value is 16...
size_t max_array_size
Specifies the maximum array size. The default is 8192 and the minimum value is 16.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
The associative array has started.
A uint32_t type integer has been read.
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
bool token_toobig
When the event is EVENT_STRING and the token is too large, stores a non-zero value. In this case, a null string is set to buf.
A float type floating-point number has been read.
static errno_t Parse(JsonStreamParser *parser, UniquePtr< MpObject > &obj) noexcept
Runs Parse(parser, obj, false).
const Token & GetToken() const noexcept
Gets the token.
Stores data on the tokens obtained by the parser.
static errno_t Parse(UniquePtr< MpObject > &obj, const char *str, const JsonStreamParserSettings &settings) noexcept
Creates MpObject by parsing JSON.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
int8_t ext
When the event is EVENT_EXT, stores a data type 8-bit value.
errno_t Init() noexcept
Initializes the parser using the default settings.
The associative array has finished.
static errno_t Parse(UniquePtr< MpObject > &obj, const char *str) noexcept
Runs Parse(obj, str, settings) with the default JsonStreamParserSettings settings specified...
size_t max_depth
Specifies the maximum value for the depth of array or associative array. The default is 7...
Format format
Decides how formats are determined when parsing. The default is FORMAT_ADAPTIVE.
An associative array key has been read.