nlib
nn::nlib::msgpack::MpWriter Class Referencefinal

Writes the MessagePack formatted data to the stream. More...

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

Public Member Functions

bool Flush () noexcept
 Flushes the write to the stream. More...
 
bool Write (const char *str) noexcept
 Writes a text string.
 
template<uint32_t n>
bool Write (const char(&str)[n]) noexcept
 See Write(const T (&vec)[n]).
 
template<class T , size_t n>
bool Write (const T(&vec)[n])
 Writes text strings or arrays. More...
 
template<class T >
bool Write (const T &tp)
 Formats strings and writes them to the display buffer. More...
 
bool Write (const void *p, size_t n) noexcept
 Writes a byte string of n bytes stored in the p parameter.
 
bool WriteArrayCount (uint32_t n) noexcept
 Writes array header information. More...
 
bool WriteMapCount (uint32_t n) noexcept
 Writes associative array header information. More...
 
bool WriteRawCount (uint32_t n) noexcept
 Writes byte array data header information. More...
 
bool WriteRawBody (const void *p, uint32_t n) noexcept
 Writes byte array data body. More...
 
bool Write (const MpObject &obj) noexcept
 See Write(const T& tp) .
 
OutputStreamGetStream () noexcept
 Gets the base stream specified in Init. More...
 
Basic Member Functions
 MpWriter () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~MpWriter () noexcept
 Destructor.
 
Initialization and Finalization
bool Init (OutputStream *stream) noexcept
 Sets a stream and initializes the object. More...
 
bool Close () noexcept
 Closes MpWriter. More...
 
Error Checking
void SetError (errno_t e) noexcept
 Sets an error. More...
 
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
 operator bool () const
 Returns true if an error has not occurred.
 

Detailed Description

Writes the MessagePack formatted data to the stream.

Description
MpWriter supports writing boxed object (MpObject), and native types.

Definition at line 30 of file MpWriter.h.

Member Function Documentation

nn::nlib::msgpack::MpWriter::Close ( )
inlinenoexcept

Closes MpWriter.

Returns
Returns true when successful.
Description
Closes MpWriter and detaches 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 42 of file MpWriter.h.

nn::nlib::msgpack::MpWriter::Flush ( )
inlinenoexcept

Flushes the write to the stream.

Returns
Returns true when successful.

Definition at line 35 of file MpWriter.h.

nn::nlib::msgpack::MpWriter::GetErrorValue ( ) const
inlinenoexcept

Gets the error value.

Return values
0No error occurred.
EILSEQMpObject is invalid.
EINVALError in an argument.
EEXISTAttempted to initialize a JsonWriter object that has already been initialized.
EIOAn error occurred in the base stream.
EBADFAttempted to use an uninitialized JsonReader.

Definition at line 52 of file MpWriter.h.

nn::nlib::msgpack::MpWriter::GetStream ( )
inlinenoexcept

Gets the base stream specified in Init.

Returns
Returns the pointer to the stream.

Definition at line 73 of file MpWriter.h.

nn::nlib::msgpack::MpWriter::Init ( OutputStream stream)
noexcept

Sets a stream and initializes the object.

Parameters
[in]streamOutput stream.
Returns
Returns true when successful.
nn::nlib::msgpack::MpWriter::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 49 of file MpWriter.h.

template<class T, size_t n>
bool nn::nlib::msgpack::MpWriter::Write ( const T(&)  vec[n])

Writes text strings or arrays.

Parameters
[in]vecArray or string to be written.
Template Parameters
TElement type.
nNumber of elements.
Returns
Returns true when successful.
Description
When T is char, the data is written as a string. Any other types are written as an array. A string must terminate with a null character.

Definition at line 122 of file MpWriter.h.

template<class T>
bool nn::nlib::msgpack::MpWriter::Write ( const T &  tp)
inline

Formats strings and writes them to the display buffer.

Template Parameters
TType of object being written.
Parameters
[in]tpObject to write to the stream.
Returns
Returns true when successful.
Description
Serializes objects and writes them to the stream. Returns true if successful. Sets an error and returns false when it fails.
Behavior differs according to the type of T. Supports serializing the following types. You may serialize user-defined types by using the MpWrite 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 133 of file MpWriter.h.

nn::nlib::msgpack::MpWriter::WriteArrayCount ( uint32_t  n)
noexcept

Writes array header information.

Parameters
[in]nNumber of arrays.
Returns
Returns true when successful.
Description
Writes array header information. Returns true if successful. Sets an error and returns false when it fails. The following URL provides examples of the information written by this function.
See also
http://wiki.msgpack.org/display/MSGPACK/Format+specification#Formatspecification-Arrays
nn::nlib::msgpack::MpWriter::WriteMapCount ( uint32_t  n)
noexcept

Writes associative array header information.

Parameters
[in]nNumber of arrays.
Returns
Returns true when successful.
Description
Writes associative array header information. Returns true if successful. Sets an error and returns false when it fails. The following URL provides examples of the information written by this function.
See also
http://wiki.msgpack.org/display/MSGPACK/Format+specification#Formatspecification-Maps
nn::nlib::msgpack::MpWriter::WriteRawBody ( const void *  p,
uint32_t  n 
)
noexcept

Writes byte array data body.

Parameters
[in]pPointer to the byte array.
[in]nSize of the byte array (in bytes).
Returns
Returns true when successful.
Description
Writes the byte array body. Returns true if successful. Sets an error and returns false when it fails. n must match the value specified in the immediately preceding WriteRawCount.
nn::nlib::msgpack::MpWriter::WriteRawCount ( uint32_t  n)
noexcept

Writes byte array data header information.

Parameters
[in]nSize of the byte array (in bytes).
Returns
Returns true when successful.
Description
Writes byte array header information. Returns true if successful. Sets an error and returns false when it fails. The following URL provides examples of the information written by this function.
See also
http://wiki.msgpack.org/display/MSGPACK/Format+specification#Formatspecification-Rawbytes

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