1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 08:15:37 +00:00

Use fixed size types for serialization

This commit is contained in:
elsid 2022-02-05 16:24:57 +01:00
parent 1b3acc85f7
commit 9584cb7ac2
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 7 additions and 5 deletions

View file

@ -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;

View file

@ -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());
}