Reads the MessagePack-formatted data from the stream.
More...
#include "nn/nlib/msgpack/MpReader.h"
|
Member function to read and convert types by converting to an object type.
|
template<class T > |
bool | Read (T v) |
| Reads data from the stream, and sets the v parameter to it. More...
|
|
template<size_t n> |
bool | Read (char(&v)[n]) noexcept |
| See Read(T (&vec)[n]) .
|
|
template<class T , size_t n> |
bool | Read (T(&v)[n]) |
| Reads text strings or arrays. More...
|
|
bool | Read (char *v, size_t n) noexcept |
| Reads a text string from the stream and sets the v parameter to it. More...
|
|
bool | Read (void *v, size_t n) noexcept |
| Reads a byte string of n bytes from the stream and sets the v parameter to it. More...
|
|
template<class T > |
bool | Read (T *v, size_t n) |
| Reads array data from the stream, and sets the v parameter to it. More...
|
|
bool | Read (MpObject *obj) noexcept |
| See Read(T v) .
|
|
bool | SkipMpObject () noexcept |
| Skips reading data equivalent to the size of one MpObject from the stream. More...
|
|
bool | CheckString (const char *key, size_t keylen) noexcept |
| Reads a single string of data from the stream, and checks whether it matches the key parameter. More...
|
|
bool | CheckString (const char *key) noexcept |
| Runs CheckString(key, nlib_strlen(key)) .
|
|
static bool | Read (MpObject *obj, const void *p, size_t n, const MpReaderSettings &settings) noexcept |
| Constructs an MpReader object, and sets MpObject from the p parameter. More...
|
|
static bool | Read (MpObject *obj, const void *p, size_t n) noexcept |
| Runs Read(MpObject* obj, const void* p, size_t n, const MpReaderSettings& settings) with settings set to the default.
|
|
Reads the MessagePack-formatted data from the stream.
- Description
MpReader
supports reading boxed objects (MpObject
) and native types.
Definition at line 43 of file MpReader.h.
nn::nlib::msgpack::MpReader::CheckString |
( |
const char * |
key, |
|
|
size_t |
keylen |
|
) |
| |
|
noexcept |
Reads a single string of data from the stream, and checks whether it matches the key parameter.
- Parameters
-
[in] | key | String. |
[in] | keylen | Length of string. |
- Returns
true
when the string matches the key parameter. false
when the string does not match, or an error occurs.
- Description
- Moves the head of the stream to the next position regardless of whether it is a match. In an associative array, the head of the stream moves to the element corresponding to the key.
nn::nlib::msgpack::MpReader::Close |
( |
| ) |
|
|
inlinenoexcept |
Closes MpReader
.
- Returns
- Returns
true
when successful.
- Description
- Closes
MpReader
and detatches the base stream. The base stream will not be closed.
- The object may be reused by calling the
Init
member function again.
Definition at line 52 of file MpReader.h.
template<class T >
nn::nlib::msgpack::MpReader::Convert |
( |
T * |
v | ) |
|
|
inline |
Converts the data read by GetNextValue
to the specified type.
- Template Parameters
-
- Parameters
-
[out] | v | Storage location for converted data. |
- Return values
-
0 | No error occurred. |
EFAULT | Returned when type conversion is not possible. v has nothing set. |
EOVERFLOW | Returned when an overflow occurs. Can be resolved when stored in a type with large size. |
EINVAL | Indicates that v is NULL . |
EIDRM | Returned when cast to a different type of data type (such as bool to a numerical value). |
- Description
- This function does not set an error state within
MpReader
.
Definition at line 74 of file MpReader.h.
nn::nlib::msgpack::MpReader::GetErrorValue |
( |
| ) |
const |
|
inlinenoexcept |
Gets the error that occurred.
- Return values
-
0 | No error occurred. |
EILSEQ | Incorrect MessagePack data encountered (parse error). |
EOF | Unexpected EOF encountered (parse error). |
EINVAL | Error in an argument. |
EEXIST | Attempted to initialize an MpReader that has already been initialized. |
EIO | An error occurred in the base stream. |
EBADF | Attempted to use an uninitialized MpReader . |
E2BIG | The size of the array (and similar items) is too big. |
ENOMEM | Failed to allocate memory. |
Definition at line 66 of file MpReader.h.
nn::nlib::msgpack::MpReader::GetNextArrayNum |
( |
size_t * |
num | ) |
|
|
noexcept |
Reads the array size data.
- Parameters
-
[out] | num | Pointer to set the number of arrays. |
- Returns
- Returns
true
when successful.
- Description
- Gets array size data from the stream and sets the num parameter to it. Sets an error and returns
false
when an error occurs.
- Returns
false
and does not set an error when the data is not array size data. In this case, nothing has been read from the stream.
nn::nlib::msgpack::MpReader::GetNextMapNum |
( |
size_t * |
num | ) |
|
|
noexcept |
Reads the associative array size data.
- Parameters
-
[out] | num | Pointer to set the number of associative arrays. |
- Returns
- Returns
true
when successful.
- Description
- Gets associative array size data from the stream and sets the num parameter to it. Sets an error and returns
false
when an error occurs.
- Returns
false
and does not set an error when the data is not associative array size data. In this case, nothing has been read from the stream.
nn::nlib::msgpack::MpReader::GetNextRawBody |
( |
void * |
p, |
|
|
size_t |
num |
|
) |
| |
|
noexcept |
Reads a byte string.
- Parameters
-
[out] | p | Where the byte string is stored. |
[in] | num | Passes the number obtained by the GetNextRawNum function. |
- Returns
- Returns
true
when successful.
nn::nlib::msgpack::MpReader::GetNextRawNum |
( |
size_t * |
num | ) |
|
|
noexcept |
Reads the byte array size data.
- Parameters
-
[out] | num | Pointer to set the byte array size. |
- Returns
- Returns
true
when successful.
- Description
- Gets byte array size data from the stream and sets the num parameter to it. Sets an error and returns
false
when an error occurs.
- Returns
false
and does not set an error when the data is not byte array size data. In this case, nothing has been read from the stream.
nn::nlib::msgpack::MpReader::GetNextValue |
( |
| ) |
|
|
noexcept |
Loads the next value data.
- Returns
- Returns
true
when successful.
- Description
- Gets the next value data from the stream, and sets it to the object's internal state. Sets an error and returns
false
when an error occurs.
- Returns
false
and does not set an error when the data is an array, an associative array, or a byte array. In this case, nothing has been read from the stream.
Specifies a configuration stream and initializes the object.
- Parameters
-
[in] | istr | Input stream to set for MpReader . |
[in] | settings | Settings for the MessagePack deserializer. |
- Returns
- Returns
true
when successful.
nn::nlib::msgpack::MpReader::Init |
( |
InputStream * |
istr | ) |
|
|
inlinenoexcept |
Initializes an object.
- Parameters
-
[in] | istr | Input stream to set for MpReader . |
- Returns
- Returns
true
when successful.
Definition at line 49 of file MpReader.h.
Constructs an MpReader
object, and sets MpObject
from the p parameter.
- Parameters
-
[in] | obj | The pointer to MpObject . Must not be NULL . |
[in] | p | Pointer to serialized data. |
[in] | n | Size of the data. |
[in] | settings | The settings to read. |
- Returns
- Returns
true
on success.
template<class T >
nn::nlib::msgpack::MpReader::Read |
( |
T |
v | ) |
|
|
inline |
Reads data from the stream, and sets the v parameter to it.
- Template Parameters
-
T | Pointer type for the type of the object to be read. |
- Parameters
-
[out] | v | Object where the data is stored after being read. |
- Returns
- Returns
true
when successful.
- Description
- T supports the following types by default. User types can be supported by specializing the
MpRead
function.
-
nil, bool
-
Signed and unsigned 8-bit to 64-bit integers.
-
float, double
-
C-style string,
std::string
-
std::pair
-
std::vector
-
Nlist
-
std::map
-
MpObject
Definition at line 79 of file MpReader.h.
template<class T , size_t n>
nn::nlib::msgpack::MpReader::Read |
( |
T(&) |
vec[n] | ) |
|
|
inline |
Reads text strings or arrays.
- Parameters
-
- Template Parameters
-
T | Element type. |
n | Number of elements. |
- Returns
- Success if
true
.
- Description
- When T is
char
, the data is read as a string. Any other types are read as an array. When it is a string, the function adds the null character and terminates.
Definition at line 89 of file MpReader.h.
nn::nlib::msgpack::MpReader::Read |
( |
char * |
v, |
|
|
size_t |
n |
|
) |
| |
|
noexcept |
Reads a text string from the stream and sets the v parameter to it.
- Parameters
-
[out] | v | Pointer to the string. |
[in] | n | Buffer size of the string (including the terminating null character). |
- Returns
- Returns
true
when successful.
- Description
- Reads the byte array as a string up to n
- 1
bytes. Sets E2BIG
as an error and returns false
when the string is longer than the n parameter. 0
is always appended to the end of the string when successful.
nn::nlib::msgpack::MpReader::Read |
( |
void * |
v, |
|
|
size_t |
n |
|
) |
| |
|
noexcept |
Reads a byte string of n bytes from the stream and sets the v parameter to it.
- Parameters
-
[out] | v | Pointer to the byte string. |
[in] | n | Byte array. |
- Returns
- Returns
true
when successful.
- Description
- Reads n bytes of a byte array. Sets
EILSEQ
as an error and returns false
when the byte array is not n bytes.
template<class T>
bool nn::nlib::msgpack::MpReader::Read |
( |
T * |
v, |
|
|
size_t |
n |
|
) |
| |
Reads array data from the stream, and sets the v parameter to it.
- Template Parameters
-
T | Pointer type for the type of the object to be read. |
- Parameters
-
[out] | v | Object where the data is stored after being read. |
[in] | n | Size of the array. |
- Returns
- Returns
true
when successful.
Definition at line 184 of file MpReader.h.
nn::nlib::msgpack::MpReader::SetError |
( |
errno_t |
e | ) |
|
|
inlinenoexcept |
Sets an error.
- Parameters
-
[in] | e | Error value to be set. (Any nonzero value is an error.) |
- Description
- It performs nothing if the error is already set.
Definition at line 63 of file MpReader.h.
nn::nlib::msgpack::MpReader::SkipMpObject |
( |
| ) |
|
|
noexcept |
Skips reading data equivalent to the size of one MpObject
from the stream.
- Returns
- Returns
true
when successful.
- Description
- Reads the byte array, but does not build an
MpObject
. As a result, this function is faster than using Read
.
The documentation for this class was generated from the following files: