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 | |
errno_t | Open (InputStream *stream) noexcept |
Specifies a stream and starts the parsing. More... | |
errno_t | Close () noexcept |
Closes the parser and sets it to the state immediately after it is initialized. More... | |
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... | |
Constructor, Destructor, and Initialization | |
constexpr | JsonStreamParser () noexcept |
Instantiates the object with default parameters (default constructor). | |
~JsonStreamParser () noexcept | |
Destructor. | |
JsonStreamParser (JsonStreamParser &&rhs) noexcept | |
Instantiates the object (move constructor). | |
JsonStreamParser & | operator= (JsonStreamParser &&rhs) noexcept |
Move assignment operator. | |
errno_t | Init (const JsonStreamParserSettings &settings) noexcept |
Initializes by specifying the behavior option. Returns 0 if successful. More... | |
errno_t | Init () noexcept |
A parameter omitted version of the above function which passes settings as the default value. | |
Error Checking | |
Error | GetError () const noexcept |
Gets an error. More... | |
operator bool () const | |
Returns true if the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside. | |
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 |
A parameter omitted version of the above function which passes nullptr as a parameter. | |
static errno_t | Parse (JsonStreamParser *parser, UniquePtr< MpObject > &obj) noexcept |
A parameter omitted version of the above function which passes false as a parameter. | |
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 |
A parameter omitted version of the above function which passes nullptr as a parameter. | |
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. | |
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 |
A parameter omitted version of the above function which passes nullptr as a parameter. | |
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. | |
static std::pair< errno_t, UniquePtr< MpObject > > | Parse (JsonStreamParser *parser, bool peek, Detail *detail) noexcept |
Creates and returns MpObject by parsing JSON or msgpack. More... | |
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 (JsonStreamParser *parser) noexcept |
A parameter omitted version of the above function which passes false as a parameter. | |
static std::pair< errno_t, UniquePtr< MpObject > > | Parse (const nlib_byte_t *first, const nlib_byte_t *last, const JsonStreamParserSettings &settings, Detail *detail) noexcept |
Creates and returns MpObject by parsing msgpack. More... | |
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. | |
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. | |
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. | |
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) . More... | |
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. | |
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. | |
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. | |
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. More... | |
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 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, UniquePtr< MpObject > > | Parse (const nlib_utf8_t *str) noexcept |
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... | |
static std::pair< errno_t, int32_t > | ToInt32 (const Token &token) noexcept |
Casts a numeric token to int32_t . More... | |
static std::pair< errno_t, uint32_t > | ToUint32 (const Token &token) noexcept |
Casts a numeric token to uint32_t . More... | |
static std::pair< errno_t, int64_t > | ToInt64 (const Token &token) noexcept |
Casts a numeric token to int64_t . More... | |
static std::pair< errno_t, uint64_t > | ToUint64 (const Token &token) noexcept |
Casts a numeric token to uint64_t . More... | |
static std::pair< errno_t, float > | ToFloat (const Token &token) noexcept |
Casts a numeric token to float . More... | |
static std::pair< errno_t, double > | ToDouble (const Token &token) noexcept |
Casts a numeric token to double . More... | |
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 parsed. More... | |
The class to parse JSON or msgpack in a pull manner.
MpObject
, the code can be simply written as follows: JsonStreamParser
before closing the stream. Definition at line 52 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 54 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 | |
---|---|
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 312 of file JsonStreamParser.h.
|
noexcept |
Initializes by specifying the behavior option. Returns 0 if successful.
[in] | settings | Behavior options. |
0 | Success. |
EALREADY | Already initialized. |
ENOMEM | Indicates that internal memory allocation failed. |
EINVAL | Indicates that the specification of behavior options was invalid. |
|
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. |
|
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 130 of file JsonStreamParser.h.
|
staticnoexcept |
Creates and returns MpObject
by parsing JSON or msgpack.
[in] | parser | Parser |
[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. |
unique_ptr<MpObject>
.true
from the second JSON onward. Normally, pass false
.
|
staticnoexcept |
Creates and returns MpObject
by parsing msgpack.
[in] | first | Pointer to the start of the msgpack byte string. |
[in] | last | Pointer to the end of the msgpack byte string. |
[in] | settings | Parameter for setting the parser. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
unique_ptr<MpObject>
.
|
inlinestaticnoexcept |
Runs Parse(walker.GetPtr(), walker.GetPtr() + walker.GetSize(), settings, detail)
.
[in] | walker | The msgpack byte string you want to parse. |
[in] | settings | Parameter for setting the parser. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
unique_ptr<MpObject>
. Definition at line 179 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Creates and returns MpObject
by parsing JSON.
[in] | str | A JSON string you want to parse. |
[in] | settings | Parameter for setting the parser. |
[out] | detail | If not NULL , the string indicating the error location is stored. |
unique_ptr<MpObject>
. Definition at line 197 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
brief A parameter omitted version of the above function which passes settings
as the default value.
Definition at line 215 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 500 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to double
.
[in] | token | Reference to the token obtained with GetToken() . |
double
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value or a value smaller than DBL_MIN
or greater than DBL_MAX
was trying to be converted. The value in second
is invalid. EDOM
, the token value was an integer which was larger than 9007199254740991LL
or smaller than -9007199254740991LL
. The value casted is set to second
. Definition at line 254 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 466 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to float
.
[in] | token | Reference to the token obtained with GetToken() . |
float
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value or a value smaller than DBL_MIN
or greater than DBL_MAX
was trying to be converted. The value in second
is invalid. ERANGE
, the value was larger than FLT_MAX
or smaller than FLT_MIN
, and the value casted is set to second
. EDOM
, the token value is an integer which is larger than 1677215
or smaller than -1677215
, or the number of double
type floating point numbers was trying to be casted. The value casted is set to second
. double
type to the float
type and EDOM
is returned. In the case of msgpack, if float 32
is parsed, this error will not be returned. Definition at line 249 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 larger than INT32_MAX or smaller than 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 329 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to int32_t
.
[in] | token | Reference to the token obtained with GetToken() . |
int32_t
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value is trying to be converted, and the value in second
is invalid. ERANGE
, the value was larger than INT32_MAX
or smaller than INT32_MIN
, and the value casted is set to second
. EDOM
, floating point numbers are converted and it is not the case where ERANGE
is to be returned. The casted value is set to second
. Definition at line 229 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 399 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to int64_t
.
[in] | token | Reference to the token obtained with GetToken() . |
int64_t
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value is trying to be converted, and the value in second
is invalid. ERANGE
, the value was larger than INT64_MAX
or smaller than INT64_MIN
, and the value casted is set to second
. EDOM
, floating point numbers are converted and it is not the case where ERANGE
is to be returned. The casted value is set to second
. Definition at line 239 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 |
Converts a timestamp to nlib_time
. It is converted only when Timestamp extension type in msgpack was parsed.
[in] | token | Reference to the token obtained with GetToken() . |
nlib_time
type value. The error value may be as follows. second
. EINVAL
, other than a timestamp is trying to be converted, and the value in second
is invalid. ERANGE
, time was not in a range that can be stored in nlib_time
. The value in second
is invalid. Definition at line 259 of file JsonStreamParser.h.
|
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 365 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to uint32_t
.
[in] | token | Reference to the token obtained with GetToken() . |
uint32_t
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value is trying to be converted, and the value in second
is invalid. ERANGE
, the value was larger than UINT32_MAX
or smaller than 0, and the value casted is set to second
. EDOM
, floating point numbers are converted and it is not the case where ERANGE
is to be returned. The casted value is set to second
. Definition at line 234 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 433 of file JsonStreamParser.h.
|
inlinestaticnoexcept |
Casts a numeric token to uint64_t
.
[in] | token | Reference to the token obtained with GetToken() . |
uint64_t
type value. The error value may be as follows. second
. EINVAL
, other than a numerical value is trying to be converted, and the value in second
is invalid. ERANGE
, the value was larger than UINT64_MAX
or smaller than 0, and the value casted is set to second
. EDOM
, floating point numbers are converted and it is not the case where ERANGE
is to be returned. The casted value is set to second
. Definition at line 244 of file JsonStreamParser.h.
© Nintendo Co., Ltd. All rights reserved.