Rework Serialization functions
add name and handle more types
This commit is contained in:
@@ -38,9 +38,6 @@ namespace Nz
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, std::string_view v);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>);
|
||||
|
||||
// Vertex processing
|
||||
class Joint;
|
||||
struct VertexStruct_XYZ_Normal_UV_Tangent;
|
||||
|
||||
54
include/Nazara/Core/BinarySerialization.hpp
Normal file
54
include/Nazara/Core/BinarySerialization.hpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
struct NAZARA_CORE_API BinarySerializationContext final
|
||||
: public SerializationContext
|
||||
{
|
||||
public:
|
||||
bool PushObject(std::string_view name) override;
|
||||
bool PopObject() override;
|
||||
bool PushArray(std::string_view name) override;
|
||||
bool PopArray() override;
|
||||
|
||||
bool Write(std::string_view name, bool value) override;
|
||||
bool Write(std::string_view name, Nz::Int8 value) override;
|
||||
bool Write(std::string_view name, Nz::Int16 value) override;
|
||||
bool Write(std::string_view name, Nz::Int32 value) override;
|
||||
bool Write(std::string_view name, Nz::Int64 value) override;
|
||||
bool Write(std::string_view name, Nz::UInt8 value) override;
|
||||
bool Write(std::string_view name, Nz::UInt16 value) override;
|
||||
bool Write(std::string_view name, Nz::UInt32 value) override;
|
||||
bool Write(std::string_view name, Nz::UInt64 value) override;
|
||||
bool Write(std::string_view name, float value) override;
|
||||
bool Write(std::string_view name, double value) override;
|
||||
bool Write(std::string_view name, const std::string& value) override;
|
||||
|
||||
bool Read(std::string_view name, bool* value) override;
|
||||
bool Read(std::string_view name, Nz::Int8* value) override;
|
||||
bool Read(std::string_view name, Nz::Int16* value) override;
|
||||
bool Read(std::string_view name, Nz::Int32* value) override;
|
||||
bool Read(std::string_view name, Nz::Int64* value) override;
|
||||
bool Read(std::string_view name, Nz::UInt8* value) override;
|
||||
bool Read(std::string_view name, Nz::UInt16* value) override;
|
||||
bool Read(std::string_view name, Nz::UInt32* value) override;
|
||||
bool Read(std::string_view name, Nz::UInt64* value) override;
|
||||
bool Read(std::string_view name, float* value) override;
|
||||
bool Read(std::string_view name, double* value) override;
|
||||
bool Read(std::string_view name, std::string* value) override;
|
||||
|
||||
MovablePtr<Stream> stream;
|
||||
Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding
|
||||
UInt8 readBitPos = 8; //< 8 means no bit is currently read
|
||||
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
|
||||
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote
|
||||
UInt8 writeByte; //< Undefined value, will be initialized at the first bit write
|
||||
|
||||
void FlushBits();
|
||||
void ResetReadBitPosition();
|
||||
void ResetWriteBitPosition();
|
||||
};
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Export.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/BinarySerialization.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
@@ -60,7 +60,7 @@ namespace Nz
|
||||
virtual void OnEmptyStream();
|
||||
|
||||
std::unique_ptr<Stream> m_ownedStream;
|
||||
SerializationContext m_context;
|
||||
BinarySerializationContext m_context;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Nz
|
||||
{
|
||||
m_context.writeBitPos = 8; //< To prevent Serialize to flush bits itself
|
||||
|
||||
if (!Serialize(m_context, m_context.writeByte))
|
||||
if (!Serialize(m_context, "bytes", m_context.writeByte))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace Nz
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
if (!Unserialize(m_context, &value))
|
||||
if (!Unserialize(m_context, "", &value))
|
||||
NazaraError("failed to serialize value");
|
||||
|
||||
return *this;
|
||||
@@ -188,7 +188,7 @@ namespace Nz
|
||||
if (!m_context.stream)
|
||||
OnEmptyStream();
|
||||
|
||||
if (!Serialize(m_context, value))
|
||||
if (!Serialize(m_context, "", value))
|
||||
NazaraError("failed to serialize value");
|
||||
|
||||
return *this;
|
||||
|
||||
@@ -711,16 +711,16 @@ namespace Nz
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, const Color& color, TypeTag<Color>)
|
||||
{
|
||||
if (!Serialize(context, color.r))
|
||||
if (!Serialize(context, "R", color.r))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.g))
|
||||
if (!Serialize(context, "G", color.g))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.b))
|
||||
if (!Serialize(context, "B", color.b))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, color.a))
|
||||
if (!Serialize(context, "A", color.a))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -735,16 +735,16 @@ namespace Nz
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, Color* color, TypeTag<Color>)
|
||||
{
|
||||
if (!Unserialize(context, &color->r))
|
||||
if (!Unserialize(context, "R", &color->r))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->g))
|
||||
if (!Unserialize(context, "G", &color->g))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->b))
|
||||
if (!Unserialize(context, "B", &color->b))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &color->a))
|
||||
if (!Unserialize(context, "A", &color->a))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -13,41 +13,106 @@
|
||||
#include <NazaraUtils/Endianness.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <NazaraUtils/TypeTag.hpp>
|
||||
#include <NazaraUtils/EnumArray.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename T>
|
||||
concept Numeric = std::is_arithmetic<T>::value;
|
||||
|
||||
struct NAZARA_CORE_API SerializationContext
|
||||
{
|
||||
MovablePtr<Stream> stream;
|
||||
Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding
|
||||
UInt8 readBitPos = 8; //< 8 means no bit is currently read
|
||||
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
|
||||
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote
|
||||
UInt8 writeByte; //< Undefined value, will be initialized at the first bit write
|
||||
public:
|
||||
virtual bool PushObject(std::string_view name) = 0;
|
||||
virtual bool PopObject() = 0;
|
||||
virtual bool PushArray(std::string_view name) = 0;
|
||||
virtual bool PopArray() = 0;
|
||||
|
||||
void FlushBits();
|
||||
inline void ResetReadBitPosition();
|
||||
inline void ResetWriteBitPosition();
|
||||
virtual bool Write(std::string_view name, bool value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::Int8 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::Int16 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::Int32 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::Int64 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::UInt8 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::UInt16 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::UInt32 value) = 0;
|
||||
virtual bool Write(std::string_view name, Nz::UInt64 value) = 0;
|
||||
virtual bool Write(std::string_view name, float value) = 0;
|
||||
virtual bool Write(std::string_view name, double value) = 0;
|
||||
virtual bool Write(std::string_view name, const std::string& value) = 0;
|
||||
|
||||
virtual bool Read(std::string_view name, bool* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::Int8* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::Int16* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::Int32* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::Int64* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::UInt8* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::UInt16* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::UInt32* value) = 0;
|
||||
virtual bool Read(std::string_view name, Nz::UInt64* value) = 0;
|
||||
virtual bool Read(std::string_view name, float* value) = 0;
|
||||
virtual bool Read(std::string_view name, double* value) = 0;
|
||||
virtual bool Read(std::string_view name, std::string* value) = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value);
|
||||
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>);
|
||||
inline bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>);
|
||||
inline bool Serialize(SerializationContext&, T, TypeTag<T>) { return false; }
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>);
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const T& value);
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value);
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
||||
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>);
|
||||
inline bool Unserialize(SerializationContext& context, std::string* value, TypeTag<std::string>);
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>);
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>);
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const T (&values)[N]);
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const std::array<T, N>& values);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>);
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const std::vector<T>& values);
|
||||
|
||||
template<typename E, typename T>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const Nz::EnumArray<E, T>& values);
|
||||
|
||||
template<Numeric T>
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>);
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline bool Unserialize(SerializationContext&, T*, TypeTag<T>) { return false; }
|
||||
|
||||
template<typename T>
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value);
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||
|
||||
template <>
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>);
|
||||
|
||||
template <>
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* value, TypeTag<std::string>);
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, T (*values)[N]);
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, std::array<T, N>* values);
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, std::vector<T>* values);
|
||||
|
||||
template<typename E, typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, Nz::EnumArray<E, T>* values);
|
||||
|
||||
template<Numeric T>
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Serialization.inl>
|
||||
|
||||
@@ -5,31 +5,22 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
*/
|
||||
inline void SerializationContext::ResetReadBitPosition()
|
||||
template<typename T>
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value)
|
||||
{
|
||||
readBitPos = 8;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
|
||||
* \remark This function only reset the cursor position, it doesn't do any writing
|
||||
if you wish to write all bits and reset bit position, call FlushBits
|
||||
|
||||
\see FlushBits
|
||||
*/
|
||||
inline void SerializationContext::ResetWriteBitPosition()
|
||||
{
|
||||
writeBitPos = 8;
|
||||
return Serialize(context, name, value, TypeTag<std::decay_t<T>>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value)
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>)
|
||||
{
|
||||
return Serialize(context, std::forward<T>(value), TypeTag<std::decay_t<T>>());
|
||||
if (!context.PushObject(name))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, value, TypeTag<std::decay_t<T>>()))
|
||||
return false;
|
||||
|
||||
return context.PopObject();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -42,21 +33,9 @@ namespace Nz
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>)
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const bool& value, TypeTag<bool>)
|
||||
{
|
||||
if (context.writeBitPos == 8)
|
||||
{
|
||||
context.writeBitPos = 0;
|
||||
context.writeByte = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
context.writeByte |= 1 << context.writeBitPos;
|
||||
|
||||
if (++context.writeBitPos >= 8)
|
||||
return Serialize(context, context.writeByte, TypeTag<UInt8>());
|
||||
else
|
||||
return true;
|
||||
return context.Write(name, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -67,12 +46,69 @@ namespace Nz
|
||||
* \param context Context for the serialization
|
||||
* \param value String to serialize
|
||||
*/
|
||||
bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>)
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const std::string& value, TypeTag<std::string>)
|
||||
{
|
||||
if (!Serialize(context, SafeCast<UInt32>(value.size()), TypeTag<UInt32>()))
|
||||
return context.Write(name, value);
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const T(&values)[N])
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
return context.stream->Write(value.data(), value.size()) == value.size();
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
{
|
||||
if (!Serialize(context, "", values[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const std::array<T, N>& values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : values)
|
||||
{
|
||||
if (!Serialize(context, "", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const std::vector<T>& values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : values)
|
||||
{
|
||||
if (!Serialize(context, "", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename E, typename T>
|
||||
bool Serialize(SerializationContext& context, std::string_view name, const Nz::EnumArray<E, T>& values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : values)
|
||||
{
|
||||
if (!Serialize(context, "", value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -85,23 +121,29 @@ namespace Nz
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>)
|
||||
template<Numeric T>
|
||||
inline bool Serialize(SerializationContext& context, std::string_view name, const T& value, TypeTag<T>)
|
||||
{
|
||||
// Flush bits in case a writing is in progress
|
||||
context.FlushBits();
|
||||
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
value = ByteSwap(value);
|
||||
|
||||
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
|
||||
return context.Write(name, value);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value)
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value)
|
||||
{
|
||||
return Unserialize(context, value, TypeTag<T>());
|
||||
return Unserialize(context, name, value, TypeTag<std::decay_t<T>>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>)
|
||||
{
|
||||
if (!context.PushObject(name))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, value, TypeTag<T>()))
|
||||
return false;
|
||||
|
||||
return context.PopObject();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -114,22 +156,9 @@ namespace Nz
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>)
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, bool* value, TypeTag<bool>)
|
||||
{
|
||||
if (context.readBitPos == 8)
|
||||
{
|
||||
if (!Unserialize(context, &context.readByte, TypeTag<UInt8>()))
|
||||
return false;
|
||||
|
||||
context.readBitPos = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
*value = (context.readByte & (1 << context.readBitPos)) != 0;
|
||||
|
||||
context.readBitPos++;
|
||||
|
||||
return true;
|
||||
return context.Read(name, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -139,14 +168,69 @@ namespace Nz
|
||||
* \param context Context of unserialization
|
||||
* \param string std::string to unserialize
|
||||
*/
|
||||
bool Unserialize(SerializationContext& context, std::string* string, TypeTag<std::string>)
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, std::string* string, TypeTag<std::string>)
|
||||
{
|
||||
UInt32 size;
|
||||
if (!Unserialize(context, &size, TypeTag<UInt32>()))
|
||||
return context.Read(name, string);
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, T(*values)[N])
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
string->resize(size);
|
||||
return context.stream->Read(&(*string)[0], size) == size;
|
||||
for (size_t i = 0; i < N; ++i)
|
||||
{
|
||||
if (!Unserialize(context, "", &(*values[i])))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename T, size_t N>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, std::array<T, N>* values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : *values)
|
||||
{
|
||||
if (!Unserialize(context, "", &value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, std::vector<T>* values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : *values)
|
||||
{
|
||||
if (!Unserialize(context, "", &value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
template<typename E, typename T>
|
||||
bool Unserialize(SerializationContext& context, std::string_view name, Nz::EnumArray<E, T>* values)
|
||||
{
|
||||
if (!context.PushArray(name))
|
||||
return false;
|
||||
|
||||
for (auto&& value : *values)
|
||||
{
|
||||
if (!Unserialize(context, "", &value))
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.PopArray();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -161,22 +245,10 @@ namespace Nz
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>)
|
||||
template<Numeric T>
|
||||
inline bool Unserialize(SerializationContext& context, std::string_view name, T* value, TypeTag<T>)
|
||||
{
|
||||
NazaraAssert(value, "Invalid data pointer");
|
||||
|
||||
context.ResetReadBitPosition();
|
||||
|
||||
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
|
||||
{
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
*value = ByteSwap(*value);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return context.Read(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace Nz
|
||||
|
||||
inline bool Serialize(SerializationContext& context, Time time, TypeTag<Time>)
|
||||
{
|
||||
if (!Serialize(context, time.m_nanoseconds))
|
||||
if (!Serialize(context, "value", time.m_nanoseconds))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -221,7 +221,7 @@ namespace Nz
|
||||
|
||||
inline bool Unserialize(SerializationContext& context, Time* time, TypeTag<Time>)
|
||||
{
|
||||
if (!Unserialize(context, &time->m_nanoseconds))
|
||||
if (!Unserialize(context, "value", &time->m_nanoseconds))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -132,16 +132,13 @@ namespace Nz
|
||||
bool Serialize(SerializationContext& context, const Uuid& value, TypeTag<Uuid>)
|
||||
{
|
||||
const std::array<Nz::UInt8, 16>& array = value.ToArray();
|
||||
if (context.stream->Write(array.data(), array.size()) != array.size())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return Serialize(context, "value", array);
|
||||
}
|
||||
|
||||
bool Unserialize(SerializationContext& context, Uuid* value, TypeTag<Uuid>)
|
||||
{
|
||||
std::array<Nz::UInt8, 16> array;
|
||||
if (context.stream->Read(array.data(), array.size()) != array.size())
|
||||
if (!Unserialize(context, "value", &array))
|
||||
return false;
|
||||
|
||||
*value = Uuid(array);
|
||||
|
||||
Reference in New Issue
Block a user