nlib
nn::nlib::msgpack::MpReader Class Referencefinal

Reads the MessagePack-formatted data from the stream. More...

#include "nn/nlib/msgpack/MpReader.h"

Public Member Functions

Initialization and Finalization
bool Init (InputStream *istr, const MpReaderSettings &settings) noexcept
 Specifies a configuration stream and initializes the object. More...
 
bool Init (InputStream *istr) noexcept
 Initializes an object. More...
 
bool Close () noexcept
 Closes MpReader. More...
 
Error Checking
void SetError (errno_t e) noexcept
 Sets an error. More...
 
errno_t GetErrorValue () const noexcept
 Gets the error that occurred. More...
 
 operator bool () const
 Returns true if an error has not occurred.
 
Low-Level Reading and Converting

Member function to read and convert types without converting to the object type.

bool GetNextValue () noexcept
 Loads the next value data. More...
 
bool GetNextArrayNum (size_t *num) noexcept
 Reads the array size data. More...
 
bool GetNextMapNum (size_t *num) noexcept
 Reads the associative array size data. More...
 
bool GetNextRawNum (size_t *num) noexcept
 Reads the byte array size data. More...
 
bool GetNextRawBody (void *p, size_t num) noexcept
 Reads a byte string. More...
 
template<class T >
errno_t Convert (T *v)
 Converts the data read by GetNextValue to the specified type. More...
 

High-Level Reading

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.
 

Detailed Description

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.

Member Function Documentation

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]keyString.
[in]keylenLength 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
TConversion target type.
Parameters
[out]vStorage location for converted data.
Return values
0No error occurred.
EFAULTReturned when type conversion is not possible. v has nothing set.
EOVERFLOWReturned when an overflow occurs. Can be resolved when stored in a type with large size.
EINVALIndicates that v is NULL.
EIDRMReturned 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
0No error occurred.
EILSEQIncorrect MessagePack data encountered (parse error).
EOFUnexpected EOF encountered (parse error).
EINVALError in an argument.
EEXISTAttempted to initialize an MpReader that has already been initialized.
EIOAn error occurred in the base stream.
EBADFAttempted to use an uninitialized MpReader.
E2BIGThe size of the array (and similar items) is too big.
ENOMEMFailed 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]numPointer 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]numPointer 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]pWhere the byte string is stored.
[in]numPasses 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]numPointer 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.
nn::nlib::msgpack::MpReader::Init ( InputStream istr,
const MpReaderSettings settings 
)
noexcept

Specifies a configuration stream and initializes the object.

Parameters
[in]istrInput stream to set for MpReader.
[in]settingsSettings for the MessagePack deserializer.
Returns
Returns true when successful.
nn::nlib::msgpack::MpReader::Init ( InputStream istr)
inlinenoexcept

Initializes an object.

Parameters
[in]istrInput stream to set for MpReader.
Returns
Returns true when successful.

Definition at line 49 of file MpReader.h.

nn::nlib::msgpack::MpReader::Read ( MpObject obj,
const void *  p,
size_t  n,
const MpReaderSettings settings 
)
staticnoexcept

Constructs an MpReader object, and sets MpObject from the p parameter.

Parameters
[in]objThe pointer to MpObject. Must not be NULL.
[in]pPointer to serialized data.
[in]nSize of the data.
[in]settingsThe settings to read.
Returns
Returns true on success.
template<class T >
nn::nlib::msgpack::MpReader::Read ( v)
inline

Reads data from the stream, and sets the v parameter to it.

Template Parameters
TPointer type for the type of the object to be read.
Parameters
[out]vObject 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
[in]vecArray.
Template Parameters
TElement type.
nNumber 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]vPointer to the string.
[in]nBuffer 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]vPointer to the byte string.
[in]nByte 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
TPointer type for the type of the object to be read.
Parameters
[out]vObject where the data is stored after being read.
[in]nSize 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]eError 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: