nlib
nn::nlib::msgpack::MpWalker Class Referencefinal

Quickly accesses MessagePack expanded in memory. More...

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

Public Member Functions

MpWalker operator[] (size_t array_idx) const noexcept
 Specifies an index and accesses the element in the array. More...
 
MpWalker operator[] (const nlib_utf8_t *key) const noexcept
 Specifies a string and accesses the element in the associative array. More...
 
MpWalker operator[] (int array_idx) const noexcept
 The same as operator[](size_t array_idx).
 
const nlib_byte_tGetPtr () const noexcept
 Gets a pointer to the current location of MessagePack data. More...
 
size_t GetSize () const noexcept
 Gets the size of the MessagePack data. More...
 
MpWalker At (size_t idx) const noexcept
 Provides the same function as operator[](size_t array_idx).
 
MpWalker At (size_t idx, const nlib_utf8_t **key, size_t *n) const noexcept
 Specifies an index and accesses the element in the associative array. More...
 
MpWalker Find (const nlib_utf8_t *key) const noexcept
 Provides the same function as operator[](const nlib_utf8_t* key).
 
MpWalker GetString (const nlib_utf8_t **str, uint32_t *n) const noexcept
 Gets the str format data. More...
 
MpWalker GetBinary (const void **bin, uint32_t *n) const noexcept
 Gets the bin format data. More...
 
MpWalker GetExt (int8_t *tp, const void **bin, uint32_t *n) const noexcept
 Gets the ext format data. More...
 
MpWalker GetMapCount (uint32_t *n) const noexcept
 Gets the associative array size. More...
 
MpWalker GetArrayCount (uint32_t *n) const noexcept
 Gets the array size. More...
 
MpWalker GetNil () const noexcept
 Gets nil. More...
 
MpWalker GetBoolean (bool *val) const noexcept
 Gets true or false. More...
 
MpWalker GetInt (int32_t *val) const noexcept
 Gets a signed integer value. More...
 
MpWalker GetInt (int64_t *val) const noexcept
 Gets a signed integer value. More...
 
MpWalker GetUint (uint32_t *val) const noexcept
 Gets an unsigned integer value. More...
 
MpWalker GetUint (uint64_t *val) const noexcept
 Gets an unsigned integer value. More...
 
MpWalker GetFloat (float *val) const noexcept
 Gets a single-precision floating-point number. More...
 
MpWalker GetDouble (double *val) const noexcept
 Gets a double-precision floating-point number. More...
 
MpWalker GetTimestamp (nlib_time *val) const noexcept
 Obtains the timestamp. More...
 
 operator bool () const
 Returns true if the object is initialized and readable.
 
Basic Member Functions
constexpr MpWalker () noexcept
 Instantiates the object with default parameters (default constructor).
 
Initialization and Finalization
constexpr MpWalker (const void *p, size_t n) noexcept
 Instantiates the object. More...
 
bool Init (const void *p, size_t n) noexcept
 Initialize with this function when using the default constructor. More...
 

Detailed Description

Quickly accesses MessagePack expanded in memory.

Description
MpObject is constructed in a tree when using MpReader to read MessagePack data. This behavior is convenient, but means that MpObject is also built for unnecessary data.
Use MessagePack data more efficiently by building the MpObject for only the necessary data. To do this, use MpWalker to specify the key of an associative array or an index of an array, move to the required location, and then use MpReader.
The following sample code describes how to construct MpObject using only information under the key attribute.
#include "nn/nlib/msgpack/MpReader.h"
...
// Cases where only the key attribute value is wanted.
const void* p = Pointer to MessagePack data
size_t n = MessagePack data size
MpWalker root(p, n);
MpWalker value = root["key"];
if (!value) { Error because attribute key was not found; }
MemoryInputStream istr(value.GetPtr(), value.GetSize());
MpReader r;
if (!r.Init(&istr)) { Initialization failed; }
MpObject obj;
if (!r.Read(&obj)) { Read failed }

Definition at line 36 of file MpWalker.h.

Constructor & Destructor Documentation

◆ MpWalker()

nn::nlib::msgpack::MpWalker::MpWalker ( const void *  p,
size_t  n 
)
inlinenoexcept

Instantiates the object.

Parameters
[in]pPointer to MessagePack data.
[in]nData size.

Definition at line 39 of file MpWalker.h.

Member Function Documentation

◆ At()

nn::nlib::msgpack::MpWalker::At ( size_t  idx,
const nlib_utf8_t **  key,
size_t *  n 
) const
noexcept

Specifies an index and accesses the element in the associative array.

Parameters
[in]idxIndex of the associative array index.
[out]keyCorresponding key of the associative array (Not null terminated).
[out]nLength of the key of the corresponding associative array.
Returns
If successful, returns the MpWalker object pointing to the value of an associative array.

◆ GetArrayCount()

nn::nlib::msgpack::MpWalker::GetArrayCount ( uint32_t *  n) const
noexcept

Gets the array size.

Parameters
[out]nSize of the array.
Returns
If successful, returns the MpWalker object pointing to the next element (the first element in the array).

◆ GetBinary()

nn::nlib::msgpack::MpWalker::GetBinary ( const void **  bin,
uint32_t *  n 
) const
noexcept

Gets the bin format data.

Parameters
[out]binPointer to the binary.
[out]nLength of the binary.
Returns
If successful, returns the MpWalker object pointing to the next element.
See also
https://github.com/msgpack/msgpack/blob/master/spec.md#formats-bin

◆ GetBoolean()

nn::nlib::msgpack::MpWalker::GetBoolean ( bool *  val) const
noexcept

Gets true or false.

Parameters
[out]valPointer to the boolean value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetDouble()

nn::nlib::msgpack::MpWalker::GetDouble ( double *  val) const
noexcept

Gets a double-precision floating-point number.

Parameters
[out]valPointer to the double-precision floating-point number.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetExt()

nn::nlib::msgpack::MpWalker::GetExt ( int8_t *  tp,
const void **  bin,
uint32_t *  n 
) const
noexcept

Gets the ext format data.

Parameters
[out]tpNumeric value indicating the object type.
[out]binPointer to the binary.
[out]nLength of the binary.
Returns
If successful, returns the MpWalker object pointing to the next element.
See also
https://github.com/msgpack/msgpack/blob/master/spec.md#formats-ext

◆ GetFloat()

nn::nlib::msgpack::MpWalker::GetFloat ( float *  val) const
noexcept

Gets a single-precision floating-point number.

Parameters
[out]valPointer to the single-precision floating-point number.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetInt() [1/2]

nn::nlib::msgpack::MpWalker::GetInt ( int32_t *  val) const
noexcept

Gets a signed integer value.

Parameters
[out]valPointer to the signed integer value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetInt() [2/2]

nn::nlib::msgpack::MpWalker::GetInt ( int64_t *  val) const
noexcept

Gets a signed integer value.

Parameters
[out]valPointer to the signed integer value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetMapCount()

nn::nlib::msgpack::MpWalker::GetMapCount ( uint32_t *  n) const
noexcept

Gets the associative array size.

Parameters
[out]nSize of the associative array.
Returns
If successful, returns the MpWalker object pointing to the next element (the first key in the associative array).

◆ GetNil()

nn::nlib::msgpack::MpWalker::GetNil ( ) const
noexcept

Gets nil.

Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetPtr()

nn::nlib::msgpack::MpWalker::GetPtr ( ) const
inlinenoexcept

Gets a pointer to the current location of MessagePack data.

Returns
Pointer to MessagePack data.

Definition at line 56 of file MpWalker.h.

◆ GetSize()

nn::nlib::msgpack::MpWalker::GetSize ( ) const
inlinenoexcept

Gets the size of the MessagePack data.

Returns
Size of the MessagePack data.

Definition at line 59 of file MpWalker.h.

◆ GetString()

nn::nlib::msgpack::MpWalker::GetString ( const nlib_utf8_t **  str,
uint32_t *  n 
) const
noexcept

Gets the str format data.

Parameters
[out]strPointer to the string (Not null terminated).
[out]nLength of the string.
Returns
If successful, returns the MpWalker object pointing to the next element.
Description
Whether the string is UTF-8 is not checked. It is the user's responsibility to check it if necessary.
See also
https://github.com/msgpack/msgpack/blob/master/spec.md#formats-str

◆ GetTimestamp()

nn::nlib::msgpack::MpWalker::GetTimestamp ( nlib_time val) const
noexcept

Obtains the timestamp.

Parameters
[out]valPointer to the time value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetUint() [1/2]

nn::nlib::msgpack::MpWalker::GetUint ( uint32_t *  val) const
noexcept

Gets an unsigned integer value.

Parameters
[out]valPointer to the unsigned integer value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ GetUint() [2/2]

nn::nlib::msgpack::MpWalker::GetUint ( uint64_t *  val) const
noexcept

Gets an unsigned integer value.

Parameters
[out]valPointer to the unsigned integer value.
Returns
If successful, returns the MpWalker object pointing to the next element.

◆ Init()

nn::nlib::msgpack::MpWalker::Init ( const void *  p,
size_t  n 
)
inlinenoexcept

Initialize with this function when using the default constructor.

Parameters
[in]pPointer to MessagePack data.
[in]nData size.
Returns
Returns true on success. (Always successful.)

Definition at line 41 of file MpWalker.h.

◆ operator[]() [1/2]

nn::nlib::msgpack::MpWalker::operator[] ( size_t  array_idx) const
noexcept

Specifies an index and accesses the element in the array.

Parameters
[in]array_idxArray index.
Returns
If successful, returns the MpWalker object pointing to the value of an array element.
Description
Returns the MpWalker indicating an array element. If not an array, or the specified index does not exist, returns an MpWalker object constructed by the default constructor.
The results can be determined by evaluating objects as shown in the code below.
MpWalker result = obj[idx];
if (!p) {
// error
}

◆ operator[]() [2/2]

nn::nlib::msgpack::MpWalker::operator[] ( const nlib_utf8_t key) const
noexcept

Specifies a string and accesses the element in the associative array.

Parameters
[in]keyAssociative array key.
Returns
If successful, returns the MpWalker object pointing to the value of an associative array.
Description
Returns the MpWalker indicating an associative array element. If not an associative array, or the specified index does not exist, returns an MpWalker object constructed by the default constructor.
The results can be determined by evaluating objects as shown in the code below.
MpWalker result = obj[idx];
if (!p) {
// error
}

The documentation for this class was generated from the following files: