nlib
nn::nlib::msgpack Namespace Reference

The library used to implement the MessagePack serializer, the JSON parser/writer, and the CSV parser. More...

Namespaces

 jsonrpc
 Implements JSON-RPC 2.0.
 

Classes

class  CsvReader
 CSV parser. Reads and parses the CSV string from the stream. More...
 
class  JsonPatch
 Class to apply JSON Patch (RFC-6902). More...
 
class  JsonPatchBuilder
 Class to create JSON Patch (RFC-6902). More...
 
class  JsonStreamGenerator
 Class for outputting JSON or msgpack. More...
 
struct  JsonStreamGeneratorSettings
 Data structure used to store the JsonStreamGenerator settings parameters. More...
 
class  JsonStreamParser
 The class to parse JSON or msgpack in a pull manner. More...
 
struct  JsonStreamParserSettings
 Data structure used to store the JsonStreamParser settings parameters. More...
 
class  MpObject
 Object created when MessagePack or JSON is read. More...
 
struct  MpObjectKv
 A pair consisting of an MpObject-type key and value. Used to store an associative array. More...
 
class  MpWalker
 Quickly accesses MessagePack expanded in memory. More...
 
struct  nil
 Class that corresponds to nil in MessagePack and null in JSON. More...
 

Functions

template<class T >
bool operator== (const nil &lhs, const T &rhs) noexcept
 Returns false if rhs is a non-nil object.
 
template<class T >
bool operator== (const T &lhs, const nil &rhs) noexcept
 Returns false if lhs is a non-nil object.
 
bool operator== (const nil &lhs, const nil &rhs) noexcept
 Returns true.
 
template<class T >
bool operator!= (const nil &rhs, const T &lhs) noexcept
 Returns true if rhs is a non-nil object.
 
template<class T >
bool operator!= (const T &rhs, const nil &lhs) noexcept
 Returns true if lhs is a non-nil object.
 
bool operator!= (const nil &rhs, const nil &lhs) noexcept
 Returns false.
 
bool operator== (const MpObjectKv &lhs, const MpObjectKv &rhs) noexcept
 Recursively compares lhs and rhs and returns true if they are equal.
 
bool operator!= (const MpObject &lhs, const MpObject &rhs) noexcept
 Recursively compares lhs and rhs and returns false if they are equal.
 
bool operator!= (const MpObjectKv &lhs, const MpObjectKv &rhs) noexcept
 Recursively compares lhs and rhs and returns false if they are equal.
 
MpObject

Free function that handles MpObject.

template<class T >
errno_t Box (MpObject *obj, const T &v)
 This function template can be specialized to define boxing the user type. More...
 
template<class T >
errno_t Unbox (const MpObject *obj, T *v)
 This function template can be specialized to define unboxing the user type. More...
 
bool operator== (const MpObject &lhs, const MpObject &rhs)
 The two MpObjects are recursively compared. Returns true if they are equivalent. More...
 

Detailed Description

The library used to implement the MessagePack serializer, the JSON parser/writer, and the CSV parser.

Description

MessagePack is one format for binary-based object serialization. MessagePack can make data transfers smaller, faster, and more flexible. The data format is similar to JSON translated into binary. MessagePack is commonly used to speed up JSON processing. Like JSON, MessagePack can be written and read in various environments such as Perl, Python, and Ruby. As a result, MessagePack can be used to communicate between different environments and languages.

About This Library
nn::nlib::msgpack contains the serializer and deserializer, the JSON parser, and the JSON generator that supports MessagePack. MessagePack data and JSON data is converted into the same data format after being read. This allows you to read JSON data and save it as MessagePack, or vice versa.
About the Compatibility of the JSON Parser With RFC 7159
This section describes the compatibility of this library's JSON parser with the RFC 7159 reference design. JSON is defined in RFC 7159.
  • About encoding, RFC 7159 requires the ability to understand UTF-8, UTF-16, and UTF-32. The msgpack library only understands UTF-8.
  • Strings that contain null characters, such as "A\u0000Z", do not cause a parsing error. This behavior is as defined in the RFC, but reading the same string as a C character string produces "A".
  • About numerals, JSON does not distinguish real numbers from integers, but attempts to understand numerals in the order of unsigned integer (uint64_t), signed integer (int64_t), and floating point value (double). Any value that is over 19 digits long, not including the sign, is read as a floating point type. The function for reading the actual value is implemented using a function including nlib_strto_int32(). We suggest handling values as strings instead of numerical values, as different JSON processors may not have uniform behavior handling very large values in JSON.
See also
https://tools.ietf.org/html/rfc7159 (RFC 7159, JSON)
http://www.7key.jp/rfc/rfc4627.html (RFC 4627, JSON, in Japanese)
https://www.ietf.org/rfc/rfc4180.txt (RFC 4180, CSV)
http://www.kasai.fm/wiki/rfc4180jp (RFC 4180, CSV, in Japanese)
http://msgpack.org/ (MessagePack)

Function Documentation

◆ Box()

template<class T >
nn::nlib::msgpack::Box ( MpObject obj,
const T &  v 
)

This function template can be specialized to define boxing the user type.

Template Parameters
TType of object to be boxed.
Parameters
[in]objObject to store the boxed data.
[in]vObject to be boxed.
Returns
Returns 0 on success.
Description
The boxing behavior can be customized using MpObject.
The following list describes implementation notes.
  • obj is passed a non-NULL value.
  • 0 must be returned when boxing is successful, and a non-zero value must be returned when it is not successful.
  • While it is possible to recursively box from this function, the return value error check must be made.

◆ operator==()

nn::nlib::msgpack::operator== ( const MpObject lhs,
const MpObject rhs 
)

The two MpObjects are recursively compared. Returns true if they are equivalent.

Recursively compares lhs and rhs and returns true if they are equal.

Parameters
[in]lhsMpObject being compared.
[in]rhsMpObject being compared.
Returns
true if they are equivalent.
Description
Usage notes are described below.
  • Slower than comparing static objects.
  • Associative arrays are not equivalent if the key order is different.
  • An error is not considered when comparing floating point types.

◆ Unbox()

template<class T >
nn::nlib::msgpack::Unbox ( const MpObject obj,
T *  v 
)

This function template can be specialized to define unboxing the user type.

Template Parameters
TObject to store the data that has been unboxed.
Parameters
[in]objObject that stores the boxed data.
[in]vObject to store the unboxed data.
Returns
Returns 0 on success.
Description
The following list describes implementation notes.
  • obj and v are passed a non-NULL value.
  • 0 must be returned when unboxing is successful, and a non-zero value must be returned when it is not successful.
  • While it is possible to recursively unbox from this function, the return value error check must be made.
  • Implement in a way that does not depend on the key order when unboxing an associative array.