-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cpp
More file actions
80 lines (54 loc) · 1.45 KB
/
Example.cpp
File metadata and controls
80 lines (54 loc) · 1.45 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
79
80
#include <cstdio>
#include "FxSerialize.hpp"
#include "FxTypes.hpp"
#include "FxHash.hpp"
struct TestStructB
{
int32 A = 5;
int32 B = 10;
//std::string Str;
FX_SERIALIZABLE_MEMBERS(A, B);
};
struct TestStructA
{
int32 X = 30;
int32 Y = 15;
float32 Z = 3;
std::string HW = "Hello, World";
bool ch = false;
TestStructB Other;
// Serializes X, Y, Z, and then serializes the `other` struct
FX_SERIALIZABLE_MEMBERS(X, Y, Z, Other, HW, ch);
};
struct TestStructC
{
int32 Value;
FX_SERIALIZABLE_MEMBERS(Value);
};
int main()
{
#ifdef FX_USE_MEMPOOL
FxMemPool::GetGlobalPool().Create(1000);
#endif
{
FxSerializerIO test_writer;
TestStructA data { 7, 3 };
data.WriteTo(FxHashStr("TestStructA"), test_writer);
TestStructC data2{100};
data2.WriteTo(FxHashStr("TestStructC"), test_writer);
test_writer.WriteToFile("Test.fxsd");
}
printf("\nReading serialized values...\n");
{
FxSerializerIO test_reader;
test_reader.ReadFromFile("Test.fxsd");
TestStructA data{};
data.ReadFrom(FxHashStr("TestStructA"), test_reader);
TestStructC data2{};
data2.ReadFrom(FxHashStr("TestStructC"), test_reader);
printf("Data2: %d\n", data2.Value);
printf("Values: {%d, %d, %f}, other.B = %d\n", data.X, data.Y, data.Z, data.Other.B);
std::cout << "Str: " << data.HW << "\n";
}
return 0;
}