-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexternal_meta.cpp
More file actions
44 lines (39 loc) · 1.05 KB
/
external_meta.cpp
File metadata and controls
44 lines (39 loc) · 1.05 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
#include <JsonFusion/serializer.hpp>
#include <JsonFusion/parser.hpp>
using JsonFusion::Annotated;
using JsonFusion::options::as_array, JsonFusion::options::exclude;
#include <iostream>
#include <format>
using std::cout;
using std::endl;
using std::format;
struct Vec {
float x = 1, y = 2, z = 3;
};
template<> struct JsonFusion::Annotated<Vec> {
using Options = OptionsPack<
as_array
>;
};
template<> struct JsonFusion::AnnotatedField<Vec, 1> {
using Options = OptionsPack<
exclude
>;
};
int main() {
struct TopLevel {
struct VecInner {
float x = 4, y = 5, z = 6;
};
Annotated<VecInner, as_array> vec1;
Vec vec2;
};
std::string out;
JsonFusion::Serialize(TopLevel{}, out);
cout << out << endl;
/* {"vec1":[4,5,6],"vec2":[1,3]} */
TopLevel t;
JsonFusion::Parse(t, out);
cout << format("vec1: ({}, {}, {}), vec2: ({}, {}, {})", t.vec1->x, t.vec1->y, t.vec1->z, t.vec2.x, t.vec2.y, t.vec2.z) << endl;
/* vec1: (4, 5, 6), vec2: (1, 2, 3) */
}