nlib
JsonStreamParser.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_
18 
19 #include <float.h>
20 #include <utility>
21 
22 #include "nn/nlib/UniquePtr.h"
23 #include "nn/nlib/Swap.h"
26 
27 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
28 #undef NLIB_VIS_PUBLIC
29 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
30 #endif
31 NLIB_NAMESPACE_BEGIN
32 class InputStream;
33 class TextReader;
34 namespace msgpack {
35 
37  enum Format { kFormatAdaptive = 0, kFormatJson, kFormatMsgpack };
39  size_t max_map_size;
41  size_t max_depth;
42  Format format;
43  bool strict;
45  max_map_size(256),
46  token_buffer_size(2048),
47  max_depth(7),
48  format(kFormatAdaptive),
49  strict(false) {}
50 };
51 
53  public:
54  enum Event {
55  kNone = -1,
56  kEventNull = 1,
71  kEventBinary, // msgpack only
72  kEventExt, // msgpack only
73  kEventEndDocument
74  };
75  enum Error {
76  kOk = 0,
77  kErrorColon,
78  kErrorComma,
79  kErrorQuote,
80  kErrorKeyTooLong,
81  kErrorNumberTooLong,
82  kErrorArrayTooBig,
83  kErrorMapTooBig,
84  kErrorCharacter,
85  kErrorNumberRange,
86  kErrorDepth,
87  kErrorToken,
88  kErrorStream
89  };
90  struct Token {
93  union {
94  uint64_t u64;
95  int64_t i64;
96  size_t size;
97  double f64;
98  int32_t i32;
99  uint32_t u32;
100  float f32;
101  } number;
103  int8_t ext; // for kEventExt
104  };
105  struct Detail {
106  nlib_utf8_t path[1024];
107  };
108 
109  public:
110  static errno_t Parse(JsonStreamParser* parser, UniquePtr<MpObject>& obj, bool peek,
112  static errno_t
114  return Parse(parser, obj, peek, nullptr);
115  }
117  return Parse(parser, obj, false);
118  }
119  static errno_t
120  Parse(UniquePtr<MpObject>& obj, const void* data, size_t n,
121  const JsonStreamParserSettings& settings, Detail* detail) NLIB_NOEXCEPT NLIB_NONNULL_2;
122  static errno_t Parse(UniquePtr<MpObject>& obj, const void* data, size_t n,
123  const JsonStreamParserSettings& settings) NLIB_NOEXCEPT {
124  return Parse(obj, data, n, settings, nullptr);
125  }
126  static errno_t Parse(UniquePtr<MpObject>& obj, const void* data, size_t n) NLIB_NOEXCEPT {
127  JsonStreamParserSettings settings;
128  return Parse(obj, data, n, settings);
129  }
130  static errno_t Parse(UniquePtr<MpObject>& obj, const nlib_utf8_t* str,
131  const JsonStreamParserSettings& settings, Detail* detail) NLIB_NOEXCEPT {
132  size_t n = nlib_strlen(str);
133  if (settings.format == JsonStreamParserSettings::kFormatJson) {
134  return Parse(obj, str, n, settings, detail);
135  } else {
136  JsonStreamParserSettings settings_ = settings;
137  settings_.format = JsonStreamParserSettings::kFormatJson;
138  return Parse(obj, str, n, settings_, detail);
139  }
140  }
141  static errno_t Parse(UniquePtr<MpObject>& obj, const nlib_utf8_t* str,
142  const JsonStreamParserSettings& settings) NLIB_NOEXCEPT {
143  return Parse(obj, str, settings, nullptr);
144  }
146  JsonStreamParserSettings settings;
147  return Parse(obj, str, settings);
148  }
149 #ifdef __cpp_rvalue_references
150  static std::pair<errno_t, UniquePtr<MpObject> >
151  Parse(JsonStreamParser* parser, bool peek, Detail* detail) NLIB_NOEXCEPT NLIB_NONNULL_1;
152  static std::pair<errno_t, UniquePtr<MpObject> >
153  Parse(JsonStreamParser* parser, bool peek) NLIB_NOEXCEPT {
154  return Parse(parser, peek, nullptr);
155  }
156  static std::pair<errno_t, UniquePtr<MpObject> > Parse(JsonStreamParser* parser) NLIB_NOEXCEPT {
157  return Parse(parser, false);
158  }
159  static std::pair<errno_t, UniquePtr<MpObject> >
160  Parse(const nlib_byte_t* first, const nlib_byte_t* last,
161  const JsonStreamParserSettings& settings,
163  static std::pair<errno_t, UniquePtr<MpObject> >
164  Parse(const nlib_byte_t* first, const nlib_byte_t* last, Detail* detail) NLIB_NOEXCEPT {
165  JsonStreamParserSettings settings;
166  return Parse(first, last, settings, detail);
167  }
168  static std::pair<errno_t, UniquePtr<MpObject> >
169  Parse(const nlib_byte_t* first, const nlib_byte_t* last,
170  const JsonStreamParserSettings& settings) NLIB_NOEXCEPT {
171  return Parse(first, last, settings, nullptr);
172  }
173  static std::pair<errno_t, UniquePtr<MpObject> >
174  Parse(const nlib_byte_t* first, const nlib_byte_t* last) NLIB_NOEXCEPT {
175  JsonStreamParserSettings settings;
176  return Parse(first, last, settings);
177  }
178  static std::pair<errno_t, UniquePtr<MpObject> >
179  Parse(const MpWalker& walker, const JsonStreamParserSettings& settings,
180  Detail* detail) NLIB_NOEXCEPT {
181  return Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, detail);
182  }
183  static std::pair<errno_t, UniquePtr<MpObject> >
184  Parse(const MpWalker& walker, Detail* detail) NLIB_NOEXCEPT {
185  JsonStreamParserSettings settings;
186  return Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, detail);
187  }
188  static std::pair<errno_t, UniquePtr<MpObject> >
189  Parse(const MpWalker& walker, const JsonStreamParserSettings& settings) NLIB_NOEXCEPT {
190  return Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, nullptr);
191  }
192  static std::pair<errno_t, UniquePtr<MpObject> > Parse(const MpWalker& walker) NLIB_NOEXCEPT {
193  JsonStreamParserSettings settings;
194  return Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, nullptr);
195  }
196  static std::pair<errno_t, UniquePtr<MpObject> >
197  Parse(const nlib_utf8_t* str, const JsonStreamParserSettings& settings,
198  Detail* detail) NLIB_NOEXCEPT {
199  const nlib_byte_t* first = reinterpret_cast<const nlib_byte_t*>(str);
200  const nlib_byte_t* last = first + nlib_strlen(str);
201  if (settings.format != JsonStreamParserSettings::kFormatJson)
202  return ::std::make_pair(EINVAL, nullptr);
203  return Parse(first, last, settings, detail);
204  }
205  static std::pair<errno_t, UniquePtr<MpObject> >
207  return Parse(str, settings, nullptr);
208  }
209  static std::pair<errno_t, UniquePtr<MpObject> >
210  Parse(const nlib_utf8_t* str, Detail* detail) NLIB_NOEXCEPT {
211  JsonStreamParserSettings settings;
212  settings.format = JsonStreamParserSettings::kFormatJson;
213  return Parse(str, settings, detail);
214  }
215  static std::pair<errno_t, UniquePtr<MpObject> > Parse(const nlib_utf8_t* str) NLIB_NOEXCEPT {
216  return Parse(str, nullptr);
217  }
218 
219 #endif
220 
221  static errno_t ToInt32(const Token& token, int32_t* number) NLIB_NOEXCEPT NLIB_NONNULL;
222  static errno_t ToUint32(const Token& token, uint32_t* number) NLIB_NOEXCEPT NLIB_NONNULL;
223  static errno_t ToInt64(const Token& token, int64_t* number) NLIB_NOEXCEPT NLIB_NONNULL;
224  static errno_t ToUint64(const Token& token, uint64_t* number) NLIB_NOEXCEPT NLIB_NONNULL;
225  static errno_t ToFloat(const Token& token, float* number) NLIB_NOEXCEPT NLIB_NONNULL;
226  static errno_t ToDouble(const Token& token, double* number) NLIB_NOEXCEPT NLIB_NONNULL;
227  static errno_t ToTimestamp(const Token& token, nlib_time* t) NLIB_NOEXCEPT NLIB_NONNULL;
228 
229  static std::pair<errno_t, int32_t> ToInt32(const Token& token) NLIB_NOEXCEPT {
230  std::pair<errno_t, int32_t> rval;
231  rval.first = ToInt32(token, &rval.second);
232  return rval;
233  }
234  static std::pair<errno_t, uint32_t> ToUint32(const Token& token) NLIB_NOEXCEPT {
235  std::pair<errno_t, uint32_t> rval;
236  rval.first = ToUint32(token, &rval.second);
237  return rval;
238  }
239  static std::pair<errno_t, int64_t> ToInt64(const Token& token) NLIB_NOEXCEPT {
240  std::pair<errno_t, int64_t> rval;
241  rval.first = ToInt64(token, &rval.second);
242  return rval;
243  }
244  static std::pair<errno_t, uint64_t> ToUint64(const Token& token) NLIB_NOEXCEPT {
245  std::pair<errno_t, uint64_t> rval;
246  rval.first = ToUint64(token, &rval.second);
247  return rval;
248  }
249  static std::pair<errno_t, float> ToFloat(const Token& token) NLIB_NOEXCEPT {
250  std::pair<errno_t, float> rval;
251  rval.first = ToFloat(token, &rval.second);
252  return rval;
253  }
254  static std::pair<errno_t, double> ToDouble(const Token& token) NLIB_NOEXCEPT {
255  std::pair<errno_t, double> rval;
256  rval.first = ToDouble(token, &rval.second);
257  return rval;
258  }
259  static std::pair<errno_t, nlib_time> ToTimestamp(const Token& token) NLIB_NOEXCEPT {
260  std::pair<errno_t, nlib_time> rval;
261  rval.first = ToTimestamp(token, &rval.second);
262  return rval;
263  }
264 
265  NLIB_CEXPR14 JsonStreamParser() NLIB_NOEXCEPT : prv_(nullptr), error_(kOk), token_() {
266  token_.event = kNone;
267  token_.buf = nullptr;
268  token_.number.u64 = 0U;
269  token_.token_toobig = false;
270  token_.ext = 0;
271  }
273 #ifdef __cpp_rvalue_references
275  error_(rhs.error_),
276  token_(rhs.token_) {
277  rhs.prv_ = nullptr;
278  }
280  prv_ = rhs.prv_;
281  rhs.prv_ = nullptr;
282  error_ = rhs.error_;
283  token_ = rhs.token_;
284  return *this;
285  }
286 #endif
288  error_(rhs.error_),
289  token_(rhs.token_) {
290  rhs.prv_ = nullptr;
291  }
292  JsonStreamParser& assign(JsonStreamParser& rhs, move_tag) NLIB_NOEXCEPT {
293  prv_ = rhs.prv_;
294  rhs.prv_ = nullptr;
295  error_ = rhs.error_;
296  token_ = rhs.token_;
297  return *this;
298  }
299  errno_t Init(const JsonStreamParserSettings& settings) NLIB_NOEXCEPT;
302  return this->Init(settings);
303  }
305  errno_t Close() NLIB_NOEXCEPT;
306  Error GetError() const NLIB_NOEXCEPT;
307  bool HasNext() const NLIB_NOEXCEPT;
308  Event Next() NLIB_NOEXCEPT;
309  bool Skip() NLIB_NOEXCEPT;
310  int GetLine() const NLIB_NOEXCEPT;
311  int GetColumn() const NLIB_NOEXCEPT;
312  const Token& GetToken() const NLIB_NOEXCEPT { return token_; }
313  NLIB_SAFE_BOOL(JsonStreamParser, error_ == kOk);
314 
315  private:
316  NLIB_VIS_HIDDEN Error ReadString() NLIB_NOEXCEPT;
317  NLIB_VIS_HIDDEN Error ReadNumber() NLIB_NOEXCEPT;
318  NLIB_VIS_HIDDEN Event NextJson() NLIB_NOEXCEPT;
319  NLIB_VIS_HIDDEN Event NextMsgpack() NLIB_NOEXCEPT;
320  NLIB_VIS_HIDDEN Event NextMsgpackVal() NLIB_NOEXCEPT;
321 
322  struct JsonStreamParserPrivate;
323  JsonStreamParserPrivate* prv_;
324  Error error_;
325  Token token_;
327 };
328 
329 inline errno_t JsonStreamParser::ToInt32(const Token& token, int32_t* number) NLIB_NOEXCEPT {
330  NLIB_EINVAL_IFNULL(number);
331  switch (token.event) {
332  case kEventNumberInt32:
333  *number = token.number.i32;
334  break;
335  case kEventNumberUint32:
336  *number = static_cast<int32_t>(token.number.u32);
337  if (token.number.u32 > INT32_MAX) return ERANGE;
338  break;
339  case kEventNumberInt64:
340  *number = static_cast<int32_t>(token.number.i64);
341  if (token.number.i64 > INT32_MAX || token.number.i64 < INT32_MIN) return ERANGE;
342  break;
343  case kEventNumberUint64:
344  *number = static_cast<int32_t>(token.number.u64);
345  if (token.number.u64 > INT32_MAX) return ERANGE;
346  break;
347  case kEventNumberFloat:
348  *number = static_cast<int32_t>(token.number.f32);
349  if (token.number.f32 > static_cast<float>(INT32_MAX) ||
350  token.number.f32 < static_cast<float>(INT32_MIN))
351  return ERANGE;
352  return EDOM;
353  case kEventNumberDouble:
354  *number = static_cast<int32_t>(token.number.f64);
355  if (token.number.f64 > static_cast<double>(INT32_MAX) ||
356  token.number.f64 < static_cast<double>(INT32_MIN))
357  return ERANGE;
358  return EDOM;
359  default:
360  return EINVAL;
361  }
362  return 0;
363 }
364 
365 inline errno_t JsonStreamParser::ToUint32(const Token& token, uint32_t* number) NLIB_NOEXCEPT {
366  NLIB_EINVAL_IFNULL(number);
367  switch (token.event) {
368  case kEventNumberInt32:
369  *number = static_cast<uint32_t>(token.number.i32);
370  if (token.number.i32 < 0) return ERANGE;
371  break;
372  case kEventNumberUint32:
373  *number = token.number.u32;
374  break;
375  case kEventNumberInt64:
376  *number = static_cast<uint32_t>(token.number.i64);
377  if (token.number.i64 > UINT32_MAX || token.number.i64 < 0) return ERANGE;
378  break;
379  case kEventNumberUint64:
380  *number = static_cast<uint32_t>(token.number.u64);
381  if (token.number.u64 > UINT32_MAX) return ERANGE;
382  break;
383  case kEventNumberFloat:
384  *number = static_cast<uint32_t>(token.number.f32);
385  if (token.number.f32 > static_cast<float>(UINT32_MAX) || token.number.f32 < 0.f)
386  return ERANGE;
387  return EDOM;
388  case kEventNumberDouble:
389  *number = static_cast<uint32_t>(token.number.f64);
390  if (token.number.f64 > static_cast<double>(UINT32_MAX) || token.number.f64 < 0.0)
391  return ERANGE;
392  return EDOM;
393  default:
394  return EINVAL;
395  }
396  return 0;
397 }
398 
399 inline errno_t JsonStreamParser::ToInt64(const Token& token, int64_t* number) NLIB_NOEXCEPT {
400  NLIB_EINVAL_IFNULL(number);
401  switch (token.event) {
402  case JsonStreamParser::kEventNumberInt32:
403  *number = token.number.i32;
404  break;
405  case JsonStreamParser::kEventNumberUint32:
406  *number = static_cast<int64_t>(token.number.u32);
407  break;
408  case JsonStreamParser::kEventNumberInt64:
409  *number = token.number.i64;
410  break;
411  case JsonStreamParser::kEventNumberUint64:
412  *number = static_cast<int64_t>(token.number.u64);
413  if (token.number.u64 > INT64_MAX) return ERANGE;
414  break;
415  case kEventNumberFloat:
416  *number = static_cast<int64_t>(token.number.f32);
417  if (token.number.f32 > static_cast<float>(INT64_MAX) ||
418  token.number.f32 < static_cast<float>(INT64_MIN))
419  return ERANGE;
420  return EDOM;
421  case kEventNumberDouble:
422  *number = static_cast<int64_t>(token.number.f64);
423  if (token.number.f64 > static_cast<double>(INT64_MAX) ||
424  token.number.f64 < static_cast<double>(INT64_MIN))
425  return ERANGE;
426  return EDOM;
427  default:
428  return EINVAL;
429  }
430  return 0;
431 }
432 
433 inline errno_t JsonStreamParser::ToUint64(const Token& token, uint64_t* number) NLIB_NOEXCEPT {
434  NLIB_EINVAL_IFNULL(number);
435  switch (token.event) {
436  case kEventNumberInt32:
437  *number = static_cast<uint64_t>(token.number.i32);
438  if (token.number.i32 < 0) return ERANGE;
439  break;
440  case kEventNumberUint32:
441  *number = token.number.u32;
442  break;
443  case kEventNumberInt64:
444  *number = static_cast<uint64_t>(token.number.i64);
445  if (token.number.i64 < 0) return ERANGE;
446  break;
447  case kEventNumberUint64:
448  *number = token.number.u64;
449  break;
450  case kEventNumberFloat:
451  *number = static_cast<uint64_t>(token.number.f32);
452  if (token.number.f32 > static_cast<float>(UINT64_MAX) || token.number.f32 < 0.f)
453  return ERANGE;
454  return EDOM;
455  case kEventNumberDouble:
456  *number = static_cast<uint64_t>(token.number.f64);
457  if (token.number.f64 > static_cast<double>(UINT64_MAX) || token.number.f64 < 0.0)
458  return ERANGE;
459  return EDOM;
460  default:
461  return EINVAL;
462  }
463  return 0;
464 }
465 
466 inline errno_t JsonStreamParser::ToFloat(const Token& token, float* number) NLIB_NOEXCEPT {
467  NLIB_EINVAL_IFNULL(number);
468  switch (token.event) {
469  case kEventNumberInt32:
470  *number = static_cast<float>(token.number.i32);
471  if (token.number.i32 > 16777215 || token.number.i32 < -16777215) return EDOM;
472  break;
473  case kEventNumberUint32:
474  *number = static_cast<float>(token.number.u32);
475  if (token.number.u32 > 16777215) return EDOM;
476  break;
477  case kEventNumberInt64:
478  *number = static_cast<float>(token.number.i64);
479  if (token.number.i64 > 16777215 || token.number.i64 < -16777215) return EDOM;
480  break;
481  case kEventNumberUint64:
482  *number = static_cast<float>(token.number.u64);
483  if (token.number.u64 > 16777215) return EDOM;
484  break;
485  case kEventNumberFloat:
486  *number = token.number.f32;
487  break;
488  case kEventNumberDouble:
489  *number = static_cast<float>(token.number.f64);
490  if (token.number.f64 < FLT_MIN || token.number.f64 > FLT_MAX)
491  return ERANGE;
492  else
493  return EDOM;
494  default:
495  return EINVAL;
496  }
497  return 0;
498 }
499 
500 inline errno_t JsonStreamParser::ToDouble(const Token& token, double* number) NLIB_NOEXCEPT {
501  NLIB_EINVAL_IFNULL(number);
502  switch (token.event) {
503  case kEventNumberInt32:
504  *number = static_cast<double>(token.number.i32);
505  break;
506  case kEventNumberUint32:
507  *number = static_cast<double>(token.number.u32);
508  break;
509  case kEventNumberInt64:
510  *number = static_cast<double>(token.number.i64);
511  if (token.number.i64 > 9007199254740991LL || token.number.i64 < -9007199254740991LL)
512  return EDOM;
513  break;
514  case kEventNumberUint64:
515  *number = static_cast<double>(token.number.u64);
516  if (token.number.u64 > 9007199254740991ULL) return EDOM;
517  break;
518  case kEventNumberFloat:
519  *number = token.number.f32;
520  break;
521  case kEventNumberDouble:
522  *number = token.number.f64;
523  break;
524  default:
525  return EINVAL;
526  }
527  return 0;
528 }
529 
530 } // namespace msgpack
531 NLIB_NAMESPACE_END
532 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonStreamParser)
533 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
534 #undef NLIB_VIS_PUBLIC
535 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
536 #endif
537 
538 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONSTREAMPARSER_H_
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_utf8_t *str) noexcept
static std::pair< errno_t, uint64_t > ToUint64(const Token &token) noexcept
Casts a numeric token to uint64_t.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_utf8_t *str, Detail *detail) noexcept
A parameter omitted version of the above function which passes settings as the default value...
static std::pair< errno_t, nlib_time > ToTimestamp(const Token &token) noexcept
Converts a timestamp to nlib_time. It is converted only when Timestamp extension type in msgpack was ...
size_t token_buffer_size
Specifies the size of the buffer to store tokens. The default is 2048 and the minimum value is 512...
Extended data has been read (msgpack only).
static std::pair< errno_t, int64_t > ToInt64(const Token &token) noexcept
Casts a numeric token to int64_t.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:183
#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...
Definition: Config.h:199
#define NLIB_NONNULL_1
Indicates that you cannot specify NULL for the first argument.
static std::pair< errno_t, float > ToFloat(const Token &token) noexcept
Casts a numeric token to float.
A uint64_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...
std::pair< errno_t, size_t > ToFloat(float *v, const StringView &str) noexcept
Internally calls nlib_float_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
Definition: StringView.h:299
nlib_utf8_t * buf
Stores strings or binary data.
In the C++11 environment (which supports alias templates), std::unique_ptr is made an alias template...
Definition: UniquePtr.h:108
Defines that class that is corresponding to std::unique_ptr.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_utf8_t *str, const JsonStreamParserSettings &settings, Detail *detail) noexcept
Creates and returns MpObject by parsing JSON.
An int32_t type integer has been read.
int64_t nlib_time
The type expressing the time in increments of 100 ns from the zero starting point of 1970-01-01...
Definition: Platform.h:452
#define NLIB_CEXPR14
constexpr is defined if C++14 constexpr is available for use. If not, holds an empty string...
Definition: Config.h:112
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:86
static errno_t Parse(UniquePtr< MpObject > &obj, const void *data, size_t n) noexcept
A parameter omitted version of the above function which passes settings as the default value...
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_utf8_t *str, const JsonStreamParserSettings &settings) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
static errno_t Parse(JsonStreamParser *parser, UniquePtr< MpObject > &obj, bool peek) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
static std::pair< errno_t, int32_t > ToInt32(const Token &token) noexcept
Casts a numeric token to int32_t.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(JsonStreamParser *parser) noexcept
A parameter omitted version of the above function which passes false as a parameter.
Event event
The event returned by Next().
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const MpWalker &walker, const JsonStreamParserSettings &settings) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
#define NLIB_NONNULL_2
Indicates that you cannot specify NULL for the second argument.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(JsonStreamParser *parser, bool peek) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const MpWalker &walker) noexcept
A parameter omitted version of the above function which passes settings as the default value...
A double type floating-point number has been read.
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:270
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_byte_t *first, const nlib_byte_t *last) noexcept
A parameter omitted version of the above function which passes settings as the default value...
Data structure used to store the JsonStreamParser settings parameters.
The class to parse JSON or msgpack in a pull manner.
static std::pair< errno_t, uint32_t > ToUint32(const Token &token) noexcept
Casts a numeric token to uint32_t.
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.
When an error occurs, the string indicating the location of the error is stored in path...
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.
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:29
An associative array key has been read.
A uint32_t type integer has been read.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_byte_t *first, const nlib_byte_t *last, const JsonStreamParserSettings &settings) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
JsonStreamParser & operator=(JsonStreamParser &&rhs) noexcept
Move assignment operator.
constexpr JsonStreamParser() noexcept
Instantiates the object with default parameters (default constructor).
static errno_t Parse(UniquePtr< MpObject > &obj, const nlib_utf8_t *str, const JsonStreamParserSettings &settings) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
JsonStreamParser(JsonStreamParser &&rhs) noexcept
Instantiates the object (move constructor).
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
bool token_toobig
When the event is kEventString and the token is too large, stores a non-zero value. In this case, a null string is set to buf.
static errno_t Parse(UniquePtr< MpObject > &obj, const nlib_utf8_t *str, const JsonStreamParserSettings &settings, Detail *detail) noexcept
Creates MpObject by parsing JSON.
std::pair< errno_t, size_t > ToDouble(double *v, const StringView &str) noexcept
Internally calls nlib_double_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
Definition: StringView.h:304
static std::pair< errno_t, double > ToDouble(const Token &token) noexcept
Casts a numeric token to double.
static errno_t Parse(JsonStreamParser *parser, UniquePtr< MpObject > &obj) noexcept
A parameter omitted version of the above function which passes false as a parameter.
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const MpWalker &walker, const JsonStreamParserSettings &settings, Detail *detail) noexcept
Runs Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, detail).
Quickly accesses MessagePack expanded in memory.
Definition: MpWalker.h:36
Stores data on the tokens obtained by the parser.
A string other than an associative array key has been read.
static errno_t Parse(UniquePtr< MpObject > &obj, const nlib_utf8_t *str) noexcept
A parameter omitted version of the above function which passes settings as the default value...
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:250
int8_t ext
When the event is kEventExt, stores a data type 8-bit value.
An int64_t type integer has been read.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const nlib_byte_t *first, const nlib_byte_t *last, Detail *detail) noexcept
A parameter omitted version of the above function which passes settings as the default value...
errno_t Init() noexcept
A parameter omitted version of the above function which passes settings as the default value...
Binary data has been read (msgpack only).
static errno_t Parse(UniquePtr< MpObject > &obj, const void *data, size_t n, const JsonStreamParserSettings &settings) noexcept
A parameter omitted version of the above function which passes nullptr as a parameter.
unsigned char nlib_byte_t
This type will be defined as std::byte in a typedef of C++17 or later.
Definition: Platform.h:314
size_t max_depth
Specifies the maximum value for the depth of array or associative array. The default is 7...
The associative array has finished.
Format format
Decides how formats are determined when parsing. The default is kFormatAdaptive.
Defines the class for reading MessagePack at high speed.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
static std::pair< errno_t, UniquePtr< MpObject > > Parse(const MpWalker &walker, Detail *detail) noexcept
A parameter omitted version of the above function which passes settings as the default value...
A float type floating-point number has been read.
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:303
StringView GetLine(StringView &str) noexcept
Obtains the strings from the start to the end of the line. Its own object ( str) moves to the beginni...
Definition: StringView.h:339
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37