|
◆ from_msgpack()
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>
Deserializes a given byte vector v to a JSON value using the MessagePack serialization format.
- Parameters
-
[in] | v | a byte vector in MessagePack format |
[in] | start_index | the index to start reading from v (0 by default) |
- Returns
- deserialized JSON value
- Exceptions
-
std::invalid_argument | if unsupported features from MessagePack were used in the given vector v or if the input is not valid MessagePack |
std::out_of_range | if the given vector ends prematurely |
- Complexity
- Linear in the size of the byte vector v.
- Example
- The example shows the deserialization of a byte vector in MessagePack format to a JSON value.
8 std::vector<uint8_t> v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63, 9 0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 17 std::cout << std::setw(2) << j << std::endl; basic_json<> json default JSON class
static basic_json from_msgpack(const std::vector< uint8_t > &v, const size_t start_index=0) create a JSON value from a byte vector in MessagePack format
Output (play with this example online): {
"compact": true,
"schema": 0
}
The example code above can be translated withg++ -std=c++11 -Isrc doc/examples/from_msgpack.cpp -o from_msgpack
- See also
- http://msgpack.org
-
to_msgpack(const basic_json&) for the analogous serialization
-
from_cbor(const std::vector<uint8_t>&, const size_t) for the related CBOR format
- Since
- version 2.0.9, parameter start_index since 2.1.1
Definition at line 7974 of file json.hpp.
|