nlib
|
The class to parse JSON or msgpack in a pull manner. More...
#include "nn/nlib/msgpack/JsonStreamParser.h"
Classes | |
struct | Detail |
When an error occurs, the string indicating the location of the error is stored in path. More... | |
struct | Token |
Stores data on the tokens obtained by the parser. More... | |
Public Types | |
enum | Event { kNone = -1, kEventNull = 1, kEventTrue, kEventFalse, kEventString, kEventNumberInt32, kEventNumberUint32, kEventNumberInt64, kEventNumberUint64, kEventNumberFloat, kEventNumberDouble, kEventStartArray, kEventEndArray, kEventStartMap, kEventEndMap, kEventKeyName, kEventBinary, kEventExt, kEventEndDocument } |
The type used by JsonStreamParser::Next() and Token , and the event that corresponds to the data read by the parser. More... | |
Public Member Functions | |
bool | HasNext () const noexcept |
If there is a subsequent state to transit (the read JSON or msgpack has not ended), true is returned. | |
Event | Next () noexcept |
Reads JSON or msgpack and transits the state in the parser. More... | |
bool | Skip () noexcept |
Skips one value, the entire array, or the entire associative array. More... | |
int | GetLine () const noexcept |
If JSON is now being read, returns the current number of rows. | |
int | GetColumn () const noexcept |
If JSON is now being read, returns the current number of digits. | |
const Token & | GetToken () const noexcept |
Gets the token. More... | |
Basic Member Functions | |
constexpr | JsonStreamParser () noexcept |
Instantiates the object with default parameters (default constructor). | |
~JsonStreamParser () noexcept | |
Destructor. | |
Initialization and Finalization | |
errno_t | Init (const JsonStreamParserSettings &settings) noexcept |
Initializes the parser. More... | |
errno_t | Init () noexcept |
Initializes the parser using the default settings. | |
errno_t | Open (InputStream *stream) noexcept |
Specifies a stream and starts the parsing. More... | |
errno_t | Open (TextReader *reader) noexcept |
Specifies the TextReader object and starts the parsing. More... | |
errno_t | Close () noexcept |
Closes the parser and sets it to the state immediately after it is initialized. More... | |
Error Checking | |
Error | GetError () const noexcept |
Gets an error. More... | |
operator bool () const | |
Returns true if an error has not occurred. | |
Static Public Member Functions | |
static errno_t | Parse (JsonStreamParser *parser, UniquePtr< MpObject > &obj, bool peek, Detail *detail) noexcept |
Creates MpObject by parsing JSON or msgpack. More... | |
static errno_t | Parse (JsonStreamParser *parser, UniquePtr< MpObject > &obj, bool peek) noexcept |
Runs Parse(parser, obj, peek, NULL) . | |
static errno_t | Parse (JsonStreamParser *parser, UniquePtr< MpObject > &obj) noexcept |
Runs Parse(parser, obj, false) . | |
static errno_t | Parse (UniquePtr< MpObject > &obj, const void *data, size_t n, const JsonStreamParserSettings &settings, Detail *detail) noexcept |
Creates MpObject by parsing JSON or msgpack. More... | |
static errno_t | Parse (UniquePtr< MpObject > &obj, const void *data, size_t n, const JsonStreamParserSettings &settings) noexcept |
Runs Parse(obj, data, n, settings, NULL) . | |
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. | |
static errno_t | Parse (UniquePtr< MpObject > &obj, const nlib_utf8_t *str, const JsonStreamParserSettings &settings, Detail *detail) noexcept |
Creates MpObject by parsing JSON. More... | |
static errno_t | Parse (UniquePtr< MpObject > &obj, const nlib_utf8_t *str, const JsonStreamParserSettings &settings) noexcept |
Runs Parse(obj, str, settings, NULL) . | |
static errno_t | Parse (UniquePtr< MpObject > &obj, const nlib_utf8_t *str) noexcept |
Runs Parse(obj, str, settings) with the default JsonStreamParserSettings settings specified. | |
Converting Parsed Numeric Values | |
Converts a numeric-type token into the specified type. | |
static errno_t | ToInt32 (const Token &token, int32_t *number) noexcept |
Casts a numeric token to int32_t . More... | |
static errno_t | ToUint32 (const Token &token, uint32_t *number) noexcept |
Casts a numeric token to uint32_t . More... | |
static errno_t | ToInt64 (const Token &token, int64_t *number) noexcept |
Casts a numeric token to int64_t . More... | |
static errno_t | ToUint64 (const Token &token, uint64_t *number) noexcept |
Casts a numeric token to uint64_t . More... | |
static errno_t | ToFloat (const Token &token, float *number) noexcept |
Casts a numeric token to float . More... | |
static errno_t | ToDouble (const Token &token, double *number) noexcept |
Casts a numeric token to double . More... | |
static errno_t | ToTimestamp (const Token &token, nlib_time *t) noexcept |
Converts a timestamp to nlib_time . More... | |
The class to parse JSON or msgpack in a pull manner.
Definition at line 55 of file JsonStreamParser.h.
The type used by JsonStreamParser::Next()
and Token
, and the event that corresponds to the data read by the parser.
Enumerator | |
---|---|
kNone | An error has occurred. |
kEventNull |
|
kEventTrue |
|
kEventFalse |
|
kEventString | A string other than an associative array key has been read. |
kEventNumberInt32 | An |
kEventNumberUint32 | A |
kEventNumberInt64 | An |
kEventNumberUint64 | A |
kEventNumberFloat | A |
kEventNumberDouble | A |
kEventStartArray | The array has started. |
kEventEndArray | The array has finished. |
kEventStartMap | The associative array has started. |
kEventEndMap | The associative array has finished. |
kEventKeyName | An associative array key has been read. |
kEventBinary | Binary data has been read (msgpack only). |
kEventExt | Extended data has been read (msgpack only). |
kEventEndDocument | JSON or msgpack has finished (A return value of |
Definition at line 57 of file JsonStreamParser.h.
|
noexcept |
Closes the parser and sets it to the state immediately after it is initialized.
0 | Success. |
TextReader
object specified with Open()
are not closed and detached from this class.
|
noexcept |
Gets an error.
JsonStreamParser
.Value | Description |
---|---|
kOk | An error has not occurred. |
kErrorColon | ':' could not be found. |
kErrorComma | ',' could not be found. |
kErrorQuote | '"' could not be found. |
kErrorKeyTooLong | The associative array key was too long to store it in the buffer for storing tokens. |
kErrorNumberTooLong | The numeric string was too long to store it in the buffer for storing tokens |
kErrorArrayTooBig | The array size exceeded the specified limit. |
kErrorMapTooBig | The associative array size exceeded the specified limit. |
kErrorCharacter | The string contains characters that are not UTF-8. |
kErrorNumberRange | The number is too large or small. |
kErrorDepth | The array and associative array depth exceeded the specified limit. |
kErrorToken | An error has occurred with other read strings. |
kErrorStream | An error has occurred with a stream. |
|
inlinenoexcept |
Gets the token.
Next()
executed just previously. Definition at line 337 of file JsonStreamParser.h.
|
noexcept |
Initializes the parser.
[in] | settings | Behavior options. |
0 | Success. |
ENOMEM | memory allocation failed. |
EALREADY | Already initialized. |
|
noexcept |
Reads JSON or msgpack and transits the state in the parser.
|
noexcept |
Specifies a stream and starts the parsing.
[in] | stream | The stream to read JSON or msgpack. |
0 | Success. |
EINVAL | Indicates that stream is NULL or JsonStreamParser is uninitialized. |
ENONEM | Memory allocation has failed. |
EALREADY | Already opened. |
|
noexcept |
Specifies the TextReader
object and starts the parsing.
[in] | reader | The TextReader object that reads JSON. |
0 | Success. |
EINVAL | Indicates that reader is NULL or uninitialized, or that JsonStreamParser is uninitialized. |
EALREADY | Already opened. |
InputStream
.
|
staticnoexcept |
Creates MpObject
by parsing JSON or msgpack.
[in] | parser | Parser |
[out] | obj | MpObject that stores the parsed results |
[in] | peek | If true , the token that has already been obtained with Next() is used for the first token. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
0
on success.
|
staticnoexcept |
Creates MpObject
by parsing JSON or msgpack.
[out] | obj | MpObject that stores the parsed results |
[in] | data | Data column that stores JSON or msgpack. |
[in] | n | Size of the data column. |
[in] | settings | Parameter for setting the parser. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
0
on success.
|
inlinestaticnoexcept |
Creates MpObject
by parsing JSON.
[out] | obj | MpObject that stores the parsed results |
[in] | str | String that stores JSON |
[in] | settings | Parameter for setting the parser. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
0
on success.JsonStreamParserSettings::kFormatJson
is specified for settings.format
. Definition at line 165 of file JsonStreamParser.h.
|
noexcept |
Skips one value, the entire array, or the entire associative array.
false
if an error occurs mid-process.
|
inlinestaticnoexcept |
Casts a numeric token to double
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
EDOM | The token value was an integer that is larger than 9007199254740991LL or smaller than -9007199254740991LL. |
Definition at line 536 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to float
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
ERANGE | The specified value was larger than FLT_MAX or smaller than FLT_MIN . |
EDOM | The token value was an integer that is larger than 1677215 or smaller than -1677215. |
ERANGE
, or EDOM
is returned, the value casted to *number is stored. Definition at line 497 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to int32_t
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
ERANGE | The specified value was smaller than INT32_MAX or INT32_MIN . |
EDOM | ERNAGE was not returned when attempting to convert a floating-point value. |
ERANGE
, or EDOM
is returned, the value casted to *number is stored. Definition at line 354 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to int64_t
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
ERANGE | The specified value was smaller than INT64_MAX or INT64_MIN . |
EDOM | ERNAGE was not returned when attempting to convert a floating-point value. |
ERANGE
, or EDOM
is returned, the value casted to *number is stored. Definition at line 428 of file JsonStreamParser.h.
|
staticnoexcept |
Converts a timestamp to nlib_time
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | t | Pointer to the converted time. |
0 | Success. |
EINVAL | t is NULL or an attempt to convert a non-timestamp value was made. |
ERANGE | The time is not within a range that can be stored in nlib_time . |
|
inlinestaticnoexcept |
Casts a numeric token to uint32_t
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
ERANGE | The specified value was larger than UINT32_MAX or smaller than 0. |
EDOM | ERNAGE was not returned when attempting to convert a floating-point value. |
ERANGE
, or EDOM
is returned, the value casted to *number is stored. Definition at line 391 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to uint64_t
.
[in] | token | Reference to the token obtained with GetToken() . |
[out] | number | Pointer to the converted numeric value. |
0 | Success. |
EINVAL | number is NULL or an attempt to convert a non-numeric value was made. |
ERANGE | The specified value was larger than UINT64_MAX or smaller than 0. |
EDOM | ERNAGE was not returned when attempting to convert a floating-point value. |
ERANGE
, or EDOM
is returned, the value casted to *number is stored. Definition at line 462 of file JsonStreamParser.h.
© 2012-2017 Nintendo Co., Ltd. All rights reserved.