Antkeeper  0.0.1
deserializer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21 #include <string>
22 
23 template <>
25 {
26  std::uint8_t temp;
27  ctx.read8(reinterpret_cast<std::byte*>(&temp), 1);
28  value = (temp) ? true : false;
29 };
30 
31 template <>
33 {
34  ctx.read8(reinterpret_cast<std::byte*>(&value), 1);
35 };
36 
37 template <>
39 {
40  ctx.read16<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
41 };
42 
43 template <>
45 {
46  ctx.read32<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
47 };
48 
49 template <>
51 {
52  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
53 };
54 
55 template <>
57 {
58  ctx.read8(reinterpret_cast<std::byte*>(&value), 1);
59 };
60 
61 template <>
63 {
64  ctx.read16<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
65 };
66 
67 template <>
69 {
70  ctx.read32<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
71 };
72 
73 template <>
75 {
76  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
77 };
78 
79 template <>
81 {
82  ctx.read32<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
83 };
84 
85 template <>
87 {
88  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&value), 1);
89 };
90 
91 template <>
93 {
94  std::uint64_t length = 0;
95  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&length), 1);
96  value.resize(static_cast<std::size_t>(length));
97  ctx.read8(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
98 };
99 
100 template <>
102 {
103  std::uint64_t length = 0;
104  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&length), 1);
105  value.resize(static_cast<std::size_t>(length));
106  ctx.read8(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
107 };
108 
109 template <>
111 {
112  std::uint64_t length = 0;
113  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&length), 1);
114  value.resize(static_cast<std::size_t>(length));
115  ctx.read16<std::endian::big>(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
116 };
117 
118 template <>
120 {
121  std::uint64_t length = 0;
122  ctx.read64<std::endian::big>(reinterpret_cast<std::byte*>(&length), 1);
123  value.resize(static_cast<std::size_t>(length));
124  ctx.read32<std::endian::big>(reinterpret_cast<std::byte*>(value.data()), static_cast<std::size_t>(length));
125 };
T length(const quaternion< T > &q)
Calculates the length of a quaternion.
Definition: quaternion.hpp:602
Provides access to a deserialization state.
std::size_t read16(std::byte *data, std::size_t count) noexcept(false)
Reads 16-bit (word) data.
std::size_t read32(std::byte *data, std::size_t count) noexcept(false)
Reads 32-bit (double word) data.
virtual std::size_t read8(std::byte *data, std::size_t count) noexcept(false)=0
Reads 8-bit (byte) data.
std::size_t read64(std::byte *data, std::size_t count) noexcept(false)
Reads 64-bit (quad word) data.
void deserialize(T &value, deserialize_context &ctx)
Deserializes a value.