From 4c982b2ffe99f5dee70657424161de9541e00a21 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Oct 2022 16:49:12 +0200 Subject: serialize: use std::bit_cast --- serialize/binary-serializer.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'serialize/binary-serializer.cpp') 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; [[maybe_unused]] static constexpr bool test1() { - constexpr std::array bytes = { 1, 0, 1, 0 }; + constexpr std::array bytes = { 1, 2, 3, 4 }; auto x = binary_reader(bytes.cbegin(), bytes.cend()); - return x.read_u().bytes[0] == 1 && - x.read_u().bytes[0] == 0 && - x.read_u().bytes[0] == 1 && - x.read_u().bytes[0] == 0; + return x.read() == 67305985; } static_assert(test1()); [[maybe_unused]] static constexpr bool test2() { - constexpr std::array bytes = { 1, 0, 1, 0 }; + constexpr std::array bytes = { 4, 3, 2, 1 }; auto r = binary_reader(bytes.cbegin(), bytes.cend()); - const auto x = r.read_u(); + const auto x = r.read(); 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()); -- cgit v1.2.3