-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArchiveTest.cpp
48 lines (38 loc) · 1.11 KB
/
ArchiveTest.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
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <iostream>
#include <sstream>
#include <string>
#include "cereal/archives/portable_binary.hpp"
// Portable binary checks endianness etc, for small overhead
namespace cereal {
template<class Archive>
void serialize(Archive& archive, glm::vec3& v) {
archive(v.x, v.y, v.z);
}
}
struct Classy {
int x;
glm::vec3 y;
template <class Archive>
void serialize(Archive& archive) {
archive(x, y);
}
};
int main() {
std::stringstream ss; // any stream can be used
{
cereal::PortableBinaryOutputArchive oarchive(ss); // Create an output archive
Classy c1_in;
c1_in.x = 12.0f;
c1_in.y.x = 69.0f;
oarchive(c1_in); // Write the data to the archive
} // archive goes out of scope, ensuring all contents are flushed
// insert networked magic here
Classy c2_in;
{
cereal::PortableBinaryInputArchive iarchive(ss); // Create an input archive
iarchive(c2_in); // Read the data from the archive
}
std::cout << c2_in.y.x << "\n";
}