-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextended.cpp
More file actions
78 lines (71 loc) · 1.56 KB
/
Copy pathextended.cpp
File metadata and controls
78 lines (71 loc) · 1.56 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "bobl/bson/decode.hpp"
#include "bobl/bson/encode.hpp"
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <string>
#include <tuple>
#include <vector>
#include <cstdint>
#include <cassert>
enum class Enum { None, One, Two, Three };
struct Simple
{
bool enabled;
int id;
std::string name;
Enum enm;
};
BOOST_FUSION_ADAPT_STRUCT(
Simple,
enabled,
id,
name,
enm)
struct Extended
{
int id;
Simple simple;
std::vector<int> ints;
std::vector<Simple> simples;
boost::variant<int,Simple, std::string, std::vector<Simple>> var;
boost::uuids::uuid uuid;
boost::optional<Enum> enm;
std::vector<std::uint8_t> binary; // this will be encoded as binary object
std::chrono::system_clock::time_point tp;
};
BOOST_FUSION_ADAPT_STRUCT(
Extended,
id,
simple,
ints,
simples,
var,
uuid,
enm,
binary,
tp)
int main()
{
boost::uuids::string_generator gen;
auto extended = Extended{ 1,
{false, 303, "the name", Enum::One },
{1,2,3},
{
{true, 1, "first", Enum::One },
{false, 2, "second", Enum::Two },
},
101,
gen("4E983010-FA64-4BAA-ABED-DD82FD691D18"),
Enum::Three,
{0x1,0x2, 0x3},
std::chrono::system_clock::now()
};
std::vector<std::uint8_t> encoded = bobl::bson::encode(extended);
auto begin = encoded.data();
auto end = begin + encoded.size();
auto extended2 = bobl::bson::decode<Extended>(begin, end);
return 0;
}