-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample_custom_2.cpp
More file actions
45 lines (33 loc) · 869 Bytes
/
sample_custom_2.cpp
File metadata and controls
45 lines (33 loc) · 869 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
39
40
41
42
43
44
45
#include <fox/serialize.hpp>
#include <iostream>
#include <format>
#include <string>
class custom_type_2
{
friend void sample_custom_2();
std::string v0_;
int v1_;
public:
custom_type_2() = default;
custom_type_2(const std::string& v0, int v1)
: v0_(v0), v1_(v1) {}
static void serialize(fox::serialize::bit_writer& writer, const custom_type_2& obj)
{
writer | obj.v0_ | obj.v1_;
}
static void deserialize(fox::serialize::bit_reader& reader, custom_type_2& obj)
{
reader | obj.v0_ | obj.v1_;
}
};
void sample_custom_2()
{
fox::serialize::bit_writer writer;
custom_type_2 a = custom_type_2("Fox", 1);
writer | a;
fox::serialize::bit_reader reader(std::from_range, writer.data());
custom_type_2 b;
reader | b;
std::cout << std::format("=== Custom Variant 2 Sample ===\nA = [{} ; {}]\nB = [{} ; {}]\n",
a.v0_, a.v1_, b.v0_, b.v1_);
}