16 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_ 17 #define INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_ 24 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 25 #undef NLIB_VIS_PUBLIC 26 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT 46 max_array_size(8192), max_map_size(256), token_buffer_size(2048), max_depth(7),
47 format(FORMAT_ADAPTIVE), strict(false) {}
108 return Parse(parser, obj,
false);
115 return Parse(obj, data, n, settings);
120 if (settings.
format == JsonStreamParserSettings::FORMAT_JSON) {
121 return Parse(obj, str, n, settings);
124 settings_.
format = JsonStreamParserSettings::FORMAT_JSON;
125 return Parse(obj, str, n, settings_);
130 return Parse(obj, str, settings);
145 return this->Init(settings);
166 struct JsonStreamParserPrivate;
167 JsonStreamParserPrivate* prv_;
173 NLIB_EINVAL_IFNULL(number);
174 switch (token.event) {
175 case EVENT_NUMBER_INT32:
176 *number = token.number.i32;
178 case EVENT_NUMBER_UINT32:
179 *number =
static_cast<int32_t
>(token.number.u32);
180 if (token.number.u32 > INT32_MAX)
return ERANGE;
182 case EVENT_NUMBER_INT64:
183 *number =
static_cast<int32_t
>(token.number.i64);
184 if (token.number.i64 > INT32_MAX ||
185 token.number.i64 < INT32_MIN)
return ERANGE;
187 case EVENT_NUMBER_UINT64:
188 *number =
static_cast<int32_t
>(token.number.u64);
189 if (token.number.u64 > INT32_MAX)
return ERANGE;
191 case EVENT_NUMBER_FLOAT:
192 *number =
static_cast<int32_t
>(token.number.f32);
193 if (token.number.f32 > static_cast<float>(INT32_MAX) ||
194 token.number.f32 <
static_cast<float>(INT32_MIN))
197 case EVENT_NUMBER_DOUBLE:
198 *number =
static_cast<int32_t
>(token.number.f64);
199 if (token.number.f64 > static_cast<double>(INT32_MAX) ||
200 token.number.f64 <
static_cast<double>(INT32_MIN))
210 NLIB_EINVAL_IFNULL(number);
211 switch (token.event) {
212 case EVENT_NUMBER_INT32:
213 *number =
static_cast<uint32_t
>(token.number.i32);
214 if (token.number.i32 < 0)
return ERANGE;
216 case EVENT_NUMBER_UINT32:
217 *number = token.number.u32;
219 case EVENT_NUMBER_INT64:
220 *number =
static_cast<uint32_t
>(token.number.i64);
221 if (token.number.i64 > UINT32_MAX ||
222 token.number.i64 < 0)
return ERANGE;
224 case EVENT_NUMBER_UINT64:
225 *number =
static_cast<uint32_t
>(token.number.u64);
226 if (token.number.u64 > UINT32_MAX)
return ERANGE;
228 case EVENT_NUMBER_FLOAT:
229 *number =
static_cast<uint32_t
>(token.number.f32);
230 if (token.number.f32 > static_cast<float>(UINT32_MAX) ||
231 token.number.f32 < 0.f)
234 case EVENT_NUMBER_DOUBLE:
235 *number =
static_cast<uint32_t
>(token.number.f64);
236 if (token.number.f64 > static_cast<double>(UINT32_MAX) ||
237 token.number.f64 < 0.0)
247 NLIB_EINVAL_IFNULL(number);
248 switch (token.event) {
249 case JsonStreamParser::EVENT_NUMBER_INT32:
250 *number = token.number.i32;
252 case JsonStreamParser::EVENT_NUMBER_UINT32:
253 *number =
static_cast<int64_t
>(token.number.u32);
255 case JsonStreamParser::EVENT_NUMBER_INT64:
256 *number = token.number.i64;
258 case JsonStreamParser::EVENT_NUMBER_UINT64:
259 *number =
static_cast<int64_t
>(token.number.u64);
260 if (token.number.u64 > INT64_MAX)
return ERANGE;
262 case EVENT_NUMBER_FLOAT:
263 *number =
static_cast<int64_t
>(token.number.f32);
264 if (token.number.f32 > static_cast<float>(INT64_MAX) ||
265 token.number.f32 <
static_cast<float>(INT64_MIN))
268 case EVENT_NUMBER_DOUBLE:
269 *number =
static_cast<int64_t
>(token.number.f64);
270 if (token.number.f64 > static_cast<double>(INT64_MAX) ||
271 token.number.f64 <
static_cast<double>(INT64_MIN))
281 NLIB_EINVAL_IFNULL(number);
282 switch (token.event) {
283 case EVENT_NUMBER_INT32:
284 *number =
static_cast<uint64_t
>(token.number.i32);
285 if (token.number.i32 < 0)
return ERANGE;
287 case EVENT_NUMBER_UINT32:
288 *number = token.number.u32;
290 case EVENT_NUMBER_INT64:
291 *number =
static_cast<uint64_t
>(token.number.i64);
292 if (token.number.i64 < 0)
return ERANGE;
294 case EVENT_NUMBER_UINT64:
295 *number = token.number.u64;
297 case EVENT_NUMBER_FLOAT:
298 *number =
static_cast<uint64_t
>(token.number.f32);
299 if (token.number.f32 > static_cast<float>(UINT64_MAX) ||
300 token.number.f32 < 0.f)
303 case EVENT_NUMBER_DOUBLE:
304 *number =
static_cast<uint64_t
>(token.number.f64);
305 if (token.number.f64 > static_cast<double>(UINT64_MAX) ||
306 token.number.f64 < 0.0)
316 NLIB_EINVAL_IFNULL(number);
317 switch (token.event) {
318 case EVENT_NUMBER_INT32:
319 *number =
static_cast<float>(token.number.i32);
320 if (token.number.i32 > 16777215 || token.number.i32 < -16777215)
323 case EVENT_NUMBER_UINT32:
324 *number =
static_cast<float>(token.number.u32);
325 if (token.number.u32 > 16777215)
328 case EVENT_NUMBER_INT64:
329 *number =
static_cast<float>(token.number.i64);
330 if (token.number.i64 > 16777215 || token.number.i64 < -16777215)
333 case EVENT_NUMBER_UINT64:
334 *number =
static_cast<float>(token.number.u64);
335 if (token.number.u64 > 16777215)
338 case EVENT_NUMBER_FLOAT:
339 *number = token.number.f32;
341 case EVENT_NUMBER_DOUBLE:
342 *number =
static_cast<float>(token.number.f32);
343 if (token.number.f64 < FLT_MIN ||
344 token.number.f64 > FLT_MAX)
355 NLIB_EINVAL_IFNULL(number);
356 switch (token.event) {
357 case EVENT_NUMBER_INT32:
358 *number =
static_cast<double>(token.number.i32);
360 case EVENT_NUMBER_UINT32:
361 *number =
static_cast<double>(token.number.u32);
363 case EVENT_NUMBER_INT64:
364 *number =
static_cast<double>(token.number.i64);
365 if (token.number.i64 > 9007199254740991LL ||
366 token.number.i64 < -9007199254740991LL)
369 case EVENT_NUMBER_UINT64:
370 *number =
static_cast<double>(token.number.u64);
371 if (token.number.u64 > 9007199254740991ULL)
374 case EVENT_NUMBER_FLOAT:
375 *number = token.number.f32;
377 case EVENT_NUMBER_DOUBLE:
378 *number = token.number.f64;
389 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS) 390 #undef NLIB_VIS_PUBLIC 391 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT 394 #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.