template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer>
Serializes a given JSON value j to a byte vector using the MessagePack serialization format. MessagePack is a binary serialization format which aims to be more compact than JSON itself, yet more efficient to parse.
- Parameters
-
[in] | j | JSON value to serialize |
- Returns
- MessagePack serialization as byte vector
- Complexity
- Linear in the size of the JSON value j.
- Example
- The example shows the serialization of a JSON value to a byte vector in MessagePack format.
8 json j = R
"({"compact": true, "schema": 0})"_json; 16 std::cout <<
"0x" << std::hex << std::setw(2) << std::setfill(
'0') << (int)byte <<
" ";
18 std::cout << std::endl;
basic_json<> json
default JSON class
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Output (play with this example online): 0x82 0xa7 0x63 0x6f 0x6d 0x70 0x61 0x63 0x74 0xc3 0xa6 0x73 0x63 0x68 0x65 0x6d 0x61 0x00
The example code above can be translated withg++ -std=c++11 -Isrc doc/examples/to_msgpack.cpp -o to_msgpack
- See also
- http://msgpack.org
-
from_msgpack(const std::vector<uint8_t>&, const size_t) for the analogous deserialization
-
to_cbor(const basic_json& for the related CBOR format
- Since
- version 2.0.9
Definition at line 7941 of file json.hpp.