forked from msgpack/msgpack-c
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unpack.cpp
43 lines (38 loc) · 1.1 KB
/
unpack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// MessagePack for C++ example
//
// Copyright (C) 2017 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <iostream>
#include <sstream>
#include <cassert>
// MSGPACK_USE_X3_PARSE should be defined before including msgpack.hpp
// It usually defined as a compiler option as -DMSGPACK_USE_X3_PARSE.
#include <msgpack.hpp>
int main() {
std::stringstream ss;
std::map<std::string, std::vector<int>> v1 {
{ "ABC", { 1, 2, 3 } },
{ "DEFG", { 4, 5 } }
};
std::vector<std::string> v2 {
"HIJ", "KLM", "NOP"
};
msgpack::pack(ss, v1);
msgpack::pack(ss, v2);
std::string const& buf = ss.str();
auto it = buf.begin();
auto end = buf.end();
{
auto oh = msgpack::unpack(it, end);
// it is updated here.
assert(v1 == (oh.get().as<std::map<std::string, std::vector<int>>>()));
}
{
auto oh = msgpack::unpack(it, end);
assert(v2 == oh.get().as<std::vector<std::string>>());
}
}