-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcexpr_bson.cpp
65 lines (55 loc) · 1.18 KB
/
cexpr_bson.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstddef>
#include <cstdint>
#include <array>
#include <cstring>
#include <iostream>
#define CONSTEXPR constexpr
//#define CONSTEXPR
//#define CONSTEXPR_OFF
#include "cexpr/bson.hpp"
#include "cexpr/atof.hpp"
#include "bson_iter.hpp"
using namespace cexpr;
int main ()
{
CEXPR_BSON_FROM_JSON(bytes, R"json(
{
"foo" : "bar",
"bar" : "baz",
"baz" : 15715755,
"neg" : -55,
"double" : -0.012423
}
)json");
CEXPR_BSON_FROM_JSON(bytes2, R"json(
{
"a" : 1,
"b" : 2,
"c" : 3,
"d" : {
"key" : "value",
"2nd" : 35,
"array" : [
1, 2, 3,
true, false,
0.0,
-1152921504606846976,
null
]
}
}
)json");
CEXPR_BSON_FROM_JSON(bytes3, R"json(
{
"only need" : "length"
}
)json");
bson_iter bi(bytes.data());
bson_iter bi2(bytes2.data());
bi.json(std::cout);
std::cout << std::endl;
bi2.json(std::cout);
std::cout << std::endl;
std::cout << "bytes3 len: " << bytes3.len() << std::endl;
return 0;
}