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 char *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 void * GetRaw (uint32_t *n) const noexcept
 Gets byte data. More...
 
const void * GetPtr () 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...
 
 operator bool () const
 Returns true if the object is initialized and readable.
 
Basic Member Functions
 MpWalker () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~MpWalker () noexcept
 Destructor.
 
Initialization and Finalization
 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.
...
// 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 17 of file MpWalker.h.

Constructor & Destructor Documentation

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

Instantiates the object.

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

Member Function Documentation

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 39 of file MpWalker.h.

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

Gets byte data.

Parameters
[out]nStores the number of bytes of the byte data.
Returns
Pointer to byte data, or NULL (if not byte data).
Description
After execution, moves the read position to immediately after the byte data.
nn::nlib::msgpack::MpWalker::GetSize ( ) const
inlinenoexcept

Gets the size of the MessagePack data.

Returns
Size of the MessagePack data.

Definition at line 40 of file MpWalker.h.

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 22 of file MpWalker.h.

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
MpWalker object.
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
}
nn::nlib::msgpack::MpWalker::operator[] ( const char *  key) const
noexcept

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

Parameters
[in]keyAssociative array key.
Returns
MpWalker object.
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: