-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializerIostreamHelper.cpp
More file actions
70 lines (54 loc) · 1.38 KB
/
SerializerIostreamHelper.cpp
File metadata and controls
70 lines (54 loc) · 1.38 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
// Copyright (c) Kobe Vrijsen 2022
// Licensed under the EUPL-1.2-or-later
#include "ConstexprSerializerBuffer.h"
#include "SerializerIostreamHelper.h"
static_assert(
[]
{
using serializer_helper::Layout;
struct MyStruct {
char a = 'a';
bool b = true;
double c = 2.47;
int d = 7;
};
using TestLayout = Layout<int, std::string, std::array<int, 3>, std::vector<MyStruct>>;
Serializer<256> io{};
// Write
{
//static_assert(JL_BINARY::detail::parse_kind<std::array<int, 3>>() != JL_BINARY::detail::eKind::invalid);
TestLayout::Write(io, 13, "Hello", { 1,2,3 }, { MyStruct{}, MyStruct{.a = 'b', .c = 3.1415 } });
}
// Read
{
int i{};
std::string str{};
std::array<int, 3> arr{};
std::vector<MyStruct> vec(size_t(2));
TestLayout::Read(io, i, str, arr, vec);
return (int)(i + str.size() + arr[0] + vec.size()); // 13 + 5 + 1 + 2 = 21
}
return 0;
}
(),
"Test layout and various serializable types"
);
using serializer_helper::Layout;
static_assert(
[]
{
// Layout
using MyLayout = Layout<std::wstring, std::vector<short>>;
// Buffer
Serializer io(128);
// Write
MyLayout::Write(io, L"ind", { 7, 13, 3, 31 });
// Read
auto const [key, val] = MyLayout::Read(io);
// Correct?
return key == L"ind"
&& std::ranges::equal(val, std::initializer_list{ 7, 13, 3, 31 });
}
(),
"Serializing a vector and wstring"
);