summaryrefslogtreecommitdiffhomepage
path: root/serialize/binary-serializer.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-29 16:49:12 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-29 16:49:12 +0200
commit4c982b2ffe99f5dee70657424161de9541e00a21 (patch)
treefd46a497140aca5c4c6d9e994dca1daa09aa8ccc /serialize/binary-serializer.cpp
parent32021bc251bf110338f28271e87964578cf07e1e (diff)
serialize: use std::bit_cast
Diffstat (limited to 'serialize/binary-serializer.cpp')
-rw-r--r--serialize/binary-serializer.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/serialize/binary-serializer.cpp b/serialize/binary-serializer.cpp
index d632febd..682ae2f5 100644
--- a/serialize/binary-serializer.cpp
+++ b/serialize/binary-serializer.cpp
@@ -34,23 +34,20 @@ template struct byte_array_iterator<sizeof(double)>;
[[maybe_unused]]
static constexpr bool test1()
{
- constexpr std::array<char, 4> bytes = { 1, 0, 1, 0 };
+ constexpr std::array<char, 4> bytes = { 1, 2, 3, 4 };
auto x = binary_reader(bytes.cbegin(), bytes.cend());
- return x.read_u<unsigned char>().bytes[0] == 1 &&
- x.read_u<unsigned char>().bytes[0] == 0 &&
- x.read_u<unsigned char>().bytes[0] == 1 &&
- x.read_u<unsigned char>().bytes[0] == 0;
+ return x.read<std::uint32_t>() == 67305985;
}
static_assert(test1());
[[maybe_unused]]
static constexpr bool test2()
{
- constexpr std::array<char, 4> bytes = { 1, 0, 1, 0 };
+ constexpr std::array<char, 4> bytes = { 4, 3, 2, 1 };
auto r = binary_reader(bytes.cbegin(), bytes.cend());
- const auto x = r.read_u<int>();
+ const auto x = r.read<std::uint32_t>();
r.assert_end();
- return x.bytes[0] == 1 && x.bytes[1] == 0 && x.bytes[2] == 1 && x.bytes[3] == 0;
+ return x == 16909060;
}
static_assert(test2());