-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_custom_0.cpp
45 lines (37 loc) · 913 Bytes
/
sample_custom_0.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
#include <fox/serialize.hpp>
#include <iostream>
#include <format>
#include <string>
template<>
struct fox::serialize::serialize_traits<std::unique_ptr<int>>
{
static void serialize(fox::serialize::bit_writer& writer, const std::unique_ptr<int>& ptr)
{
writer | (static_cast<bool>(ptr));
if (ptr)
writer | (*ptr);
}
static void deserialize(fox::serialize::bit_reader& reader, std::unique_ptr<int>& ptr)
{
bool b = fox::serialize::deserialize<bool>(reader);
if(b)
{
ptr = std::make_unique<int>(fox::serialize::deserialize<int>(reader));
}
else
{
ptr.reset();
}
}
};
void sample_custom_0()
{
fox::serialize::bit_writer writer;
auto a = std::make_unique<int>(2);
writer | a;
fox::serialize::bit_reader reader(std::from_range, writer.data());
std::unique_ptr<int> b;
reader | b;
std::cout << std::format("=== Custom Variant 0 Sample ===\nA = {}\nB = {}\n",
*a, *b);
}