Use fixed size types for serialization

C++20
elsid 3 years ago
parent 1b3acc85f7
commit 9584cb7ac2
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -5,6 +5,7 @@
#include <utility>
#include <type_traits>
#include <cstdint>
namespace SerializationTesting
{
@ -20,7 +21,7 @@ namespace SerializationTesting
}
};
enum Enum
enum Enum : std::int32_t
{
A,
B,
@ -30,7 +31,7 @@ namespace SerializationTesting
struct Composite
{
short mFloatArray[3] = {0};
std::vector<int> mIntVector;
std::vector<std::int32_t> mIntVector;
std::vector<Enum> mEnumVector;
std::vector<Pod> mPodVector;
std::size_t mPodDataSize = 0;

@ -7,6 +7,7 @@
#include <type_traits>
#include <utility>
#include <vector>
#include <cstdint>
namespace Serialization
{
@ -51,13 +52,13 @@ namespace Serialization
-> std::enable_if_t<isContiguousContainer<T>>
{
if constexpr (mode == Mode::Write)
visitor(self(), value.size());
visitor(self(), static_cast<std::uint64_t>(value.size()));
else
{
static_assert(mode == Mode::Read);
std::size_t size = 0;
std::uint64_t size = 0;
visitor(self(), size);
value.resize(size);
value.resize(static_cast<std::size_t>(size));
}
self()(std::forward<Visitor>(visitor), value.data(), value.size());
}

Loading…
Cancel
Save