-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample_custom_4.cpp
More file actions
38 lines (27 loc) · 833 Bytes
/
sample_custom_4.cpp
File metadata and controls
38 lines (27 loc) · 833 Bytes
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
#include <fox/serialize.hpp>
#include <iostream>
#include <format>
#include <string>
class custom_type_4
{
friend void sample_custom_4();
std::string v0_;
int v1_;
public:
custom_type_4() = default;
custom_type_4(const std::string& v0, int v1)
: v0_(v0), v1_(v1) {}
// This can be a hand written trait like in a sample samples/sample_custom_0.cpp
using serialize_trait = fox::serialize::serialize_from_members<custom_type_4, &custom_type_4::v0_, &custom_type_4::v1_>;
};
void sample_custom_4()
{
fox::serialize::bit_writer writer;
custom_type_4 a = custom_type_4("Fox", 1);
writer | a;
fox::serialize::bit_reader reader(std::from_range, writer.data());
custom_type_4 b;
reader | b;
std::cout << std::format("=== Custom Variant 4 Sample ===\nA = [{} ; {}]\nB = [{} ; {}]\n",
a.v0_, a.v1_, b.v0_, b.v1_);
}