Rework Serialization functions
add name and handle more types
This commit is contained in:
parent
055634e77c
commit
a0f2b128d7
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -767,7 +767,7 @@ namespace Nz
|
|||
template<AngleUnit Unit, typename T>
|
||||
bool Serialize(SerializationContext& context, Angle<Unit, T> angle, TypeTag<Angle<Unit, T>>)
|
||||
{
|
||||
if (!Serialize(context, angle.value))
|
||||
if (!Serialize(context, "value", angle.value))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -783,7 +783,7 @@ namespace Nz
|
|||
template<AngleUnit Unit, typename T>
|
||||
bool Unserialize(SerializationContext& context, Angle<Unit, T>* angle, TypeTag<Angle<Unit, T>>)
|
||||
{
|
||||
if (!Unserialize(context, &angle->value))
|
||||
if (!Unserialize(context, "value", &angle->value))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -421,13 +421,13 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const BoundingVolume<T>& boundingVolume, TypeTag<BoundingVolume<T>>)
|
||||
{
|
||||
if (!Serialize(context, static_cast<UInt8>(boundingVolume.extent)))
|
||||
if (!Serialize(context, "extent", static_cast<UInt8>(boundingVolume.extent)))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, boundingVolume.aabb))
|
||||
if (!Serialize(context, "aabb", boundingVolume.aabb))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, boundingVolume.obb))
|
||||
if (!Serialize(context, "obb", boundingVolume.obb))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -446,7 +446,7 @@ namespace Nz
|
|||
bool Unserialize(SerializationContext& context, BoundingVolume<T>* boundingVolume, TypeTag<BoundingVolume<T>>)
|
||||
{
|
||||
UInt8 extend;
|
||||
if (!Unserialize(context, &extend))
|
||||
if (!Unserialize(context, "extent", &extend))
|
||||
return false;
|
||||
|
||||
if (extend > UnderlyingCast(Extent::Max))
|
||||
|
|
@ -454,10 +454,10 @@ namespace Nz
|
|||
|
||||
boundingVolume->extent = static_cast<Extent>(extend);
|
||||
|
||||
if (!Unserialize(context, &boundingVolume->aabb))
|
||||
if (!Unserialize(context, "aabb", &boundingVolume->aabb))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &boundingVolume->obb))
|
||||
if (!Unserialize(context, "obb", &boundingVolume->obb))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -754,22 +754,22 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Box<T>& box, TypeTag<Box<T>>)
|
||||
{
|
||||
if (!Serialize(context, box.x))
|
||||
if (!Serialize(context, "x", box.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, box.y))
|
||||
if (!Serialize(context, "y", box.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, box.z))
|
||||
if (!Serialize(context, "z", box.z))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, box.width))
|
||||
if (!Serialize(context, "width", box.width))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, box.height))
|
||||
if (!Serialize(context, "height", box.height))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, box.depth))
|
||||
if (!Serialize(context, "depth", box.depth))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -785,22 +785,22 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Box<T>* box, TypeTag<Box<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &box->x))
|
||||
if (!Unserialize(context, "x", &box->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &box->y))
|
||||
if (!Unserialize(context, "y", &box->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &box->z))
|
||||
if (!Unserialize(context, "z", &box->z))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &box->width))
|
||||
if (!Unserialize(context, "width", &box->width))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &box->height))
|
||||
if (!Unserialize(context, "height", &box->height))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &box->depth))
|
||||
if (!Unserialize(context, "depth", &box->depth))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -294,13 +294,13 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const EulerAngles<T>& angles, TypeTag<EulerAngles<T>>)
|
||||
{
|
||||
if (!Serialize(context, angles.pitch))
|
||||
if (!Serialize(context, "pitch", angles.pitch))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, angles.yaw))
|
||||
if (!Serialize(context, "yaw", angles.yaw))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, angles.roll))
|
||||
if (!Serialize(context, "roll", angles.roll))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -316,13 +316,13 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, EulerAngles<T>* angles, TypeTag<EulerAngles<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &angles->pitch))
|
||||
if (!Unserialize(context, "pitch", &angles->pitch))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &angles->yaw))
|
||||
if (!Unserialize(context, "yaw", &angles->yaw))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &angles->roll))
|
||||
if (!Unserialize(context, "roll", &angles->roll))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -608,13 +608,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Frustum<T>& frustum, TypeTag<Frustum<T>>)
|
||||
{
|
||||
for (const auto& plane : frustum.m_planes)
|
||||
{
|
||||
if (!Serialize(context, plane))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Serialize(context, "planes", frustum.m_planes);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -627,13 +621,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Frustum<T>* frustum, TypeTag<Frustum<T>>)
|
||||
{
|
||||
for (auto& plane : frustum->m_planes)
|
||||
{
|
||||
if (!Unserialize(context, &plane))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Unserialize(context, "planes", &frustum->m_planes);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -1368,7 +1368,7 @@ namespace Nz
|
|||
{
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
{
|
||||
if (!Serialize(context, matrix[i]))
|
||||
if (!Serialize(context, "", matrix[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1388,7 +1388,7 @@ namespace Nz
|
|||
T* head = &matrix->m11;
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
{
|
||||
if (!Unserialize(context, head + i))
|
||||
if (!Unserialize(context, "", head + i))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -217,16 +217,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const OrientedBox<T>& obb, TypeTag<OrientedBox<T>>)
|
||||
{
|
||||
if (!Serialize(context, obb.localBox))
|
||||
if (!Serialize(context, "localBox", obb.localBox))
|
||||
return false;
|
||||
|
||||
for (auto&& corner : obb.m_corners)
|
||||
{
|
||||
if (!Serialize(context, corner))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Serialize(context, "corners", obb.m_corners);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -239,16 +233,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, OrientedBox<T>* obb, TypeTag<OrientedBox<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &obb->localBox))
|
||||
if (!Unserialize(context, "localBox", &obb->localBox))
|
||||
return false;
|
||||
|
||||
for (auto&& corner : obb->m_corners)
|
||||
{
|
||||
if (!Unserialize(context, &corner))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Unserialize(context, "corners", &obb->m_corners);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Plane<T>& plane, TypeTag<Plane<T>>)
|
||||
{
|
||||
if (!Serialize(context, plane.normal))
|
||||
if (!Serialize(context, "normal", plane.normal))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, plane.distance))
|
||||
if (!Serialize(context, "distance", plane.distance))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -301,10 +301,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Plane<T>* plane, TypeTag<Plane<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &plane->normal))
|
||||
if (!Unserialize(context, "normal", &plane->normal))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &plane->distance))
|
||||
if (!Unserialize(context, "distance", &plane->distance))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -788,16 +788,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Quaternion<T>& quat, TypeTag<Quaternion<T>>)
|
||||
{
|
||||
if (!Serialize(context, quat.x))
|
||||
if (!Serialize(context, "x", quat.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, quat.y))
|
||||
if (!Serialize(context, "y", quat.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, quat.z))
|
||||
if (!Serialize(context, "z", quat.z))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, quat.w))
|
||||
if (!Serialize(context, "w", quat.w))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -813,16 +813,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Quaternion<T>* quat, TypeTag<Quaternion<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &quat->x))
|
||||
if (!Unserialize(context, "x", &quat->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &quat->y))
|
||||
if (!Unserialize(context, "y", &quat->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &quat->z))
|
||||
if (!Unserialize(context, "z", &quat->z))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &quat->w))
|
||||
if (!Unserialize(context, "w", &quat->w))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -575,10 +575,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Ray<T>& ray, TypeTag<Ray<T>>)
|
||||
{
|
||||
if (!Serialize(context, ray.origin))
|
||||
if (!Serialize(context, "origin", ray.origin))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, ray.direction))
|
||||
if (!Serialize(context, "direction", ray.direction))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -594,10 +594,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Ray<T>* ray, TypeTag<Ray<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &ray->origin))
|
||||
if (!Unserialize(context, "origin", &ray->origin))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &ray->direction))
|
||||
if (!Unserialize(context, "direction", &ray->direction))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -625,16 +625,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Rect<T>& rect, TypeTag<Rect<T>>)
|
||||
{
|
||||
if (!Serialize(context, rect.x))
|
||||
if (!Serialize(context, "x", rect.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, rect.y))
|
||||
if (!Serialize(context, "y", rect.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, rect.width))
|
||||
if (!Serialize(context, "width", rect.width))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, rect.height))
|
||||
if (!Serialize(context, "height", rect.height))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -650,16 +650,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Rect<T>* rect, TypeTag<Rect<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &rect->x))
|
||||
if (!Unserialize(context, "x", &rect->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &rect->y))
|
||||
if (!Unserialize(context, "y", &rect->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &rect->width))
|
||||
if (!Unserialize(context, "width", &rect->width))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &rect->height))
|
||||
if (!Unserialize(context, "height", &rect->height))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -507,16 +507,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Sphere<T>& sphere, TypeTag<Sphere<T>>)
|
||||
{
|
||||
if (!Serialize(context, sphere.x))
|
||||
if (!Serialize(context, "x", sphere.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, sphere.y))
|
||||
if (!Serialize(context, "y", sphere.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, sphere.z))
|
||||
if (!Serialize(context, "z", sphere.z))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, sphere.radius))
|
||||
if (!Serialize(context, "radius", sphere.radius))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -532,16 +532,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Sphere<T>* sphere, TypeTag<Sphere<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &sphere->x))
|
||||
if (!Unserialize(context, "x", &sphere->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &sphere->y))
|
||||
if (!Unserialize(context, "y", &sphere->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &sphere->z))
|
||||
if (!Unserialize(context, "z", &sphere->z))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &sphere->radius))
|
||||
if (!Unserialize(context, "radius", &sphere->radius))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -775,10 +775,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Vector2<T>& vector, TypeTag<Vector2<T>>)
|
||||
{
|
||||
if (!Serialize(context, vector.x))
|
||||
if (!Serialize(context, "x", vector.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.y))
|
||||
if (!Serialize(context, "y", vector.y))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -794,10 +794,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Vector2<T>* vector, TypeTag<Vector2<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &vector->x))
|
||||
if (!Unserialize(context, "x", &vector->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->y))
|
||||
if (!Unserialize(context, "y", &vector->y))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -956,13 +956,13 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Vector3<T>& vector, TypeTag<Vector3<T>>)
|
||||
{
|
||||
if (!Serialize(context, vector.x))
|
||||
if (!Serialize(context, "x", vector.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.y))
|
||||
if (!Serialize(context, "y", vector.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.z))
|
||||
if (!Serialize(context, "z", vector.z))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -978,13 +978,13 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Vector3<T>* vector, TypeTag<Vector3<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &vector->x))
|
||||
if (!Unserialize(context, "x", &vector->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->y))
|
||||
if (!Unserialize(context, "y", &vector->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->z))
|
||||
if (!Unserialize(context, "z", &vector->z))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -758,16 +758,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, const Vector4<T>& vector, TypeTag<Vector4<T>>)
|
||||
{
|
||||
if (!Serialize(context, vector.x))
|
||||
if (!Serialize(context, "x", vector.x))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.y))
|
||||
if (!Serialize(context, "y", vector.y))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.z))
|
||||
if (!Serialize(context, "z", vector.z))
|
||||
return false;
|
||||
|
||||
if (!Serialize(context, vector.w))
|
||||
if (!Serialize(context, "w", vector.w))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -783,16 +783,16 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, Vector4<T>* vector, TypeTag<Vector4<T>>)
|
||||
{
|
||||
if (!Unserialize(context, &vector->x))
|
||||
if (!Unserialize(context, "x", &vector->x))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->y))
|
||||
if (!Unserialize(context, "y", &vector->y))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->z))
|
||||
if (!Unserialize(context, "z", &vector->z))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &vector->w))
|
||||
if (!Unserialize(context, "w", &vector->w))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,188 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Export.hpp
|
||||
|
||||
#include <Nazara/Core/BinarySerialization.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
*/
|
||||
void BinarySerializationContext::ResetReadBitPosition()
|
||||
{
|
||||
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
|
||||
*/
|
||||
void BinarySerializationContext::ResetWriteBitPosition()
|
||||
{
|
||||
writeBitPos = 8;
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::PushObject(std::string_view name)
|
||||
{
|
||||
// do nothing
|
||||
NazaraUnused(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::PopObject()
|
||||
{
|
||||
// do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::PushArray(std::string_view name)
|
||||
{
|
||||
// do nothing
|
||||
NazaraUnused(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::PopArray()
|
||||
{
|
||||
// do nothing
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::SerializationContext
|
||||
* \brief Structure containing a serialization/unserialization context states
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Write bits to the stream (if any) and reset the current bit cursor
|
||||
|
||||
* \see ResetWriteBitPosition
|
||||
*/
|
||||
void BinarySerializationContext::FlushBits()
|
||||
{
|
||||
if (writeBitPos != 8)
|
||||
{
|
||||
ResetWriteBitPosition();
|
||||
|
||||
// Serialize will reset the bit position
|
||||
if (!Serialize(*this, "", writeByte))
|
||||
NazaraWarning("Failed to flush bits");
|
||||
}
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::Write(std::string_view name, bool value)
|
||||
{
|
||||
if (writeBitPos == 8)
|
||||
{
|
||||
writeBitPos = 0;
|
||||
writeByte = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
writeByte |= 1 << writeBitPos;
|
||||
|
||||
if (++writeBitPos >= 8)
|
||||
return Serialize(*this, name, writeByte, TypeTag<UInt8>());
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
#define WRITE_NUMERIC(Type) \
|
||||
bool BinarySerializationContext::Write(std::string_view name, Type value) \
|
||||
{ \
|
||||
NazaraUnused(name); \
|
||||
/* Flush bits in case a writing is in progress */ \
|
||||
FlushBits(); \
|
||||
\
|
||||
if (endianness != Endianness::Unknown && endianness != PlatformEndianness) \
|
||||
value = ByteSwap(value); \
|
||||
\
|
||||
return stream->Write(&value, sizeof(Type)) == sizeof(Type); \
|
||||
}
|
||||
|
||||
WRITE_NUMERIC(Nz::Int8);
|
||||
WRITE_NUMERIC(Nz::Int16);
|
||||
WRITE_NUMERIC(Nz::Int32);
|
||||
WRITE_NUMERIC(Nz::Int64);
|
||||
WRITE_NUMERIC(Nz::UInt8);
|
||||
WRITE_NUMERIC(Nz::UInt16);
|
||||
WRITE_NUMERIC(Nz::UInt32);
|
||||
WRITE_NUMERIC(Nz::UInt64);
|
||||
WRITE_NUMERIC(float);
|
||||
WRITE_NUMERIC(double);
|
||||
|
||||
#undef WRITE_NUMERIC
|
||||
|
||||
bool BinarySerializationContext::Write(std::string_view name, const std::string& value)
|
||||
{
|
||||
NazaraUnused(name);
|
||||
if (!Serialize(*this, "", SafeCast<UInt32>(value.size()), TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
return stream->Write(value.data(), value.size()) == value.size();
|
||||
}
|
||||
|
||||
bool BinarySerializationContext::Read(std::string_view name, bool* value)
|
||||
{
|
||||
if (readBitPos == 8)
|
||||
{
|
||||
if (!Unserialize(*this, name, &readByte, TypeTag<UInt8>()))
|
||||
return false;
|
||||
|
||||
readBitPos = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
*value = (readByte & (1 << readBitPos)) != 0;
|
||||
|
||||
readBitPos++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define READ_NUMERIC(Type) \
|
||||
bool BinarySerializationContext::Read(std::string_view name, Type* value) \
|
||||
{ \
|
||||
NazaraUnused(name); \
|
||||
NazaraAssert(value, "Invalid data pointer"); \
|
||||
ResetReadBitPosition(); \
|
||||
if (stream->Read(value, sizeof(Type)) == sizeof(Type)) \
|
||||
{ \
|
||||
if (endianness != Endianness::Unknown && endianness != PlatformEndianness) \
|
||||
*value = ByteSwap(*value); \
|
||||
return true; \
|
||||
} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
READ_NUMERIC(Nz::Int8);
|
||||
READ_NUMERIC(Nz::Int16);
|
||||
READ_NUMERIC(Nz::Int32);
|
||||
READ_NUMERIC(Nz::Int64);
|
||||
READ_NUMERIC(Nz::UInt8);
|
||||
READ_NUMERIC(Nz::UInt16);
|
||||
READ_NUMERIC(Nz::UInt32);
|
||||
READ_NUMERIC(Nz::UInt64);
|
||||
READ_NUMERIC(float);
|
||||
READ_NUMERIC(double);
|
||||
|
||||
#undef READ_NUMERIC
|
||||
|
||||
bool BinarySerializationContext::Read(std::string_view name, std::string* value)
|
||||
{
|
||||
NazaraUnused(name);
|
||||
UInt32 size;
|
||||
if (!Unserialize(*this, "", &size, TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
value->resize(size);
|
||||
return stream->Read(&(*value)[0], size) == size;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,37 +8,30 @@ namespace Nz
|
|||
{
|
||||
bool Unserialize(SerializationContext& context, DDSHeader* header)
|
||||
{
|
||||
if (!Unserialize(context, &header->size))
|
||||
if (!Unserialize(context, "size", &header->size))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->flags))
|
||||
if (!Unserialize(context, "flags", &header->flags))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->height))
|
||||
if (!Unserialize(context, "height", &header->height))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->width))
|
||||
if (!Unserialize(context, "width", &header->width))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->pitch))
|
||||
if (!Unserialize(context, "pitch", &header->pitch))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->depth))
|
||||
if (!Unserialize(context, "depth", &header->depth))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->levelCount))
|
||||
if (!Unserialize(context, "levels", &header->levelCount))
|
||||
return false;
|
||||
if (!Unserialize(context, "reserved1", &header->reserved1))
|
||||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < CountOf(header->reserved1); ++i)
|
||||
{
|
||||
if (!Unserialize(context, &header->reserved1[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Unserialize(context, &header->format))
|
||||
if (!Unserialize(context, "format", &header->format))
|
||||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < CountOf(header->ddsCaps); ++i)
|
||||
{
|
||||
if (!Unserialize(context, &header->ddsCaps[i]))
|
||||
return false;
|
||||
}
|
||||
if (!Unserialize(context, "caps", &header->ddsCaps))
|
||||
return false;
|
||||
|
||||
if (!Unserialize(context, &header->reserved2))
|
||||
if (!Unserialize(context, "reserved2", &header->reserved2))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -48,19 +41,19 @@ namespace Nz
|
|||
{
|
||||
UInt32 enumValue;
|
||||
|
||||
if (!Unserialize(context, &enumValue))
|
||||
if (!Unserialize(context, "format", &enumValue))
|
||||
return false;
|
||||
header->dxgiFormat = static_cast<DXGI_FORMAT>(enumValue);
|
||||
|
||||
if (!Unserialize(context, &enumValue))
|
||||
if (!Unserialize(context, "dimension", &enumValue))
|
||||
return false;
|
||||
header->resourceDimension = static_cast<D3D10_RESOURCE_DIMENSION>(enumValue);
|
||||
|
||||
if (!Unserialize(context, &header->miscFlag))
|
||||
if (!Unserialize(context, "miscFlag", &header->miscFlag))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->arraySize))
|
||||
if (!Unserialize(context, "size", &header->arraySize))
|
||||
return false;
|
||||
if (!Unserialize(context, &header->reserved))
|
||||
if (!Unserialize(context, "reserved", &header->reserved))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -68,21 +61,21 @@ namespace Nz
|
|||
|
||||
bool Unserialize(SerializationContext& context, DDSPixelFormat* pixelFormat)
|
||||
{
|
||||
if (!Unserialize(context, &pixelFormat->size))
|
||||
if (!Unserialize(context, "size", &pixelFormat->size))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->flags))
|
||||
if (!Unserialize(context, "flags", &pixelFormat->flags))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->fourCC))
|
||||
if (!Unserialize(context, "CC", &pixelFormat->fourCC))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->bpp))
|
||||
if (!Unserialize(context, "bpp", &pixelFormat->bpp))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->redMask))
|
||||
if (!Unserialize(context, "redMask", &pixelFormat->redMask))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->greenMask))
|
||||
if (!Unserialize(context, "greenMask", &pixelFormat->greenMask))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->blueMask))
|
||||
if (!Unserialize(context, "blueMask", &pixelFormat->blueMask))
|
||||
return false;
|
||||
if (!Unserialize(context, &pixelFormat->alphaMask))
|
||||
if (!Unserialize(context, "alphaMask", &pixelFormat->alphaMask))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Export.hpp
|
||||
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::SerializationContext
|
||||
* \brief Structure containing a serialization/unserialization context states
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Write bits to the stream (if any) and reset the current bit cursor
|
||||
|
||||
* \see ResetWriteBitPosition
|
||||
*/
|
||||
void SerializationContext::FlushBits()
|
||||
{
|
||||
if (writeBitPos != 8)
|
||||
{
|
||||
ResetWriteBitPosition();
|
||||
|
||||
// Serialize will reset the bit position
|
||||
if (!Serialize(*this, writeByte))
|
||||
NazaraWarning("Failed to flush bits");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Core/BinarySerialization.hpp>
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/MemoryView.hpp>
|
||||
|
|
@ -17,7 +17,7 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
std::array<char, 256> datas; // The array must be bigger than any of the serializable classes
|
||||
Nz::MemoryView stream(datas.data(), datas.size());
|
||||
|
||||
Nz::SerializationContext context;
|
||||
Nz::BinarySerializationContext context;
|
||||
context.stream = &stream;
|
||||
|
||||
WHEN("We serialize basic types")
|
||||
|
|
@ -25,21 +25,21 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
THEN("Arithmetical types")
|
||||
{
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Serialize(context, 3));
|
||||
REQUIRE(Serialize(context, "", 3));
|
||||
int value = 0;
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &value));
|
||||
REQUIRE(Unserialize(context, "", &value));
|
||||
REQUIRE(value == 3);
|
||||
}
|
||||
|
||||
THEN("Boolean type")
|
||||
{
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Serialize(context, true));
|
||||
REQUIRE(Serialize(context, "", true));
|
||||
context.FlushBits(); //< Don't forget to flush bits (it is NOT done by the stream)
|
||||
context.stream->SetCursorPos(0);
|
||||
bool value = false;
|
||||
REQUIRE(Unserialize(context, &value));
|
||||
REQUIRE(Unserialize(context, "", &value));
|
||||
REQUIRE(value == true);
|
||||
}
|
||||
}
|
||||
|
|
@ -51,11 +51,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::BoundingVolumef nullVolume = Nz::BoundingVolumef::Null();
|
||||
Nz::BoundingVolumef copy(nullVolume);
|
||||
REQUIRE(Serialize(context, nullVolume));
|
||||
REQUIRE(Serialize(context, "", nullVolume));
|
||||
nullVolume = Nz::BoundingVolumef::Infinite();
|
||||
REQUIRE(nullVolume != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &nullVolume));
|
||||
REQUIRE(Unserialize(context, "", &nullVolume));
|
||||
REQUIRE(nullVolume == copy);
|
||||
}
|
||||
|
||||
|
|
@ -64,11 +64,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Boxf zeroBox = Nz::Boxf::Zero();
|
||||
Nz::Boxf copy(zeroBox);
|
||||
REQUIRE(Serialize(context, zeroBox));
|
||||
REQUIRE(Serialize(context, "", zeroBox));
|
||||
zeroBox = Nz::Boxf(1, 1, 1, 1, 1, 1);
|
||||
REQUIRE(zeroBox != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroBox));
|
||||
REQUIRE(Unserialize(context, "", &zeroBox));
|
||||
REQUIRE(zeroBox == copy);
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +77,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::EulerAnglesf zeroEuler = Nz::EulerAnglesf::Zero();
|
||||
Nz::EulerAnglesf copy(zeroEuler);
|
||||
REQUIRE(Serialize(context, zeroEuler));
|
||||
REQUIRE(Serialize(context, "", zeroEuler));
|
||||
zeroEuler = Nz::EulerAnglesf(10, 24, 6); // Random values
|
||||
REQUIRE(zeroEuler != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroEuler));
|
||||
REQUIRE(Unserialize(context, "", &zeroEuler));
|
||||
REQUIRE(zeroEuler == copy);
|
||||
}
|
||||
|
||||
|
|
@ -90,12 +90,12 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Frustumf frustum = Nz::Frustumf::Build(10, 10, 10, 100, Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ()); // Random values
|
||||
Nz::Frustumf copy(frustum);
|
||||
REQUIRE(Serialize(context, frustum));
|
||||
REQUIRE(Serialize(context, "", frustum));
|
||||
frustum = Nz::Frustumf::Build(50, 40, 20, 100, Nz::Vector3f::UnitX(), Nz::Vector3f::UnitZ());
|
||||
for (std::size_t i = 0; i < Nz::FrustumPlaneCount; ++i)
|
||||
REQUIRE(frustum.GetPlane(static_cast<Nz::FrustumPlane>(i)) != copy.GetPlane(static_cast<Nz::FrustumPlane>(i)));
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &frustum));
|
||||
REQUIRE(Unserialize(context, "", &frustum));
|
||||
for (std::size_t i = 0; i < Nz::FrustumPlaneCount; ++i)
|
||||
REQUIRE(frustum.GetPlane(static_cast<Nz::FrustumPlane>(i)) == copy.GetPlane(static_cast<Nz::FrustumPlane>(i)));
|
||||
}
|
||||
|
|
@ -105,11 +105,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Matrix4f zeroMatrix = Nz::Matrix4f::Zero();
|
||||
Nz::Matrix4f copy(zeroMatrix);
|
||||
REQUIRE(Serialize(context, zeroMatrix));
|
||||
REQUIRE(Serialize(context, "", zeroMatrix));
|
||||
zeroMatrix = Nz::Matrix4f::Identity(); // Random values
|
||||
REQUIRE(zeroMatrix != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroMatrix));
|
||||
REQUIRE(Unserialize(context, "", &zeroMatrix));
|
||||
REQUIRE(zeroMatrix == copy);
|
||||
}
|
||||
|
||||
|
|
@ -120,13 +120,13 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
zeroOBB.Update(Nz::Vector3f::Zero());
|
||||
|
||||
Nz::OrientedBoxf copy(zeroOBB);
|
||||
REQUIRE(Serialize(context, zeroOBB));
|
||||
REQUIRE(Serialize(context, "", zeroOBB));
|
||||
zeroOBB = Nz::OrientedBoxf(Nz::Boxf(1, 1, 1, 1, 1, 1)); // Random values
|
||||
zeroOBB.Update(Nz::Vector3f::Zero());
|
||||
|
||||
REQUIRE(zeroOBB != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroOBB));
|
||||
REQUIRE(Unserialize(context, "", &zeroOBB));
|
||||
REQUIRE(zeroOBB == copy);
|
||||
}
|
||||
|
||||
|
|
@ -135,11 +135,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Planef planeXY = Nz::Planef::XY();
|
||||
Nz::Planef copy(planeXY);
|
||||
REQUIRE(Serialize(context, planeXY));
|
||||
REQUIRE(Serialize(context, "", planeXY));
|
||||
planeXY = Nz::Planef::YZ();
|
||||
REQUIRE(planeXY != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &planeXY));
|
||||
REQUIRE(Unserialize(context, "", &planeXY));
|
||||
REQUIRE(planeXY == copy);
|
||||
}
|
||||
|
||||
|
|
@ -148,11 +148,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Quaternionf quaternionIdentity = Nz::Quaternionf::Identity();
|
||||
Nz::Quaternionf copy(quaternionIdentity);
|
||||
REQUIRE(Serialize(context, quaternionIdentity));
|
||||
REQUIRE(Serialize(context, "", quaternionIdentity));
|
||||
quaternionIdentity = Nz::Quaternionf::Zero();
|
||||
REQUIRE(quaternionIdentity != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &quaternionIdentity));
|
||||
REQUIRE(Unserialize(context, "", &quaternionIdentity));
|
||||
REQUIRE(quaternionIdentity == copy);
|
||||
}
|
||||
|
||||
|
|
@ -161,11 +161,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Rayf axisX = Nz::Rayf::AxisX();
|
||||
Nz::Rayf copy(axisX);
|
||||
REQUIRE(Serialize(context, axisX));
|
||||
REQUIRE(Serialize(context, "", axisX));
|
||||
axisX = Nz::Rayf::AxisY();
|
||||
REQUIRE(axisX != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &axisX));
|
||||
REQUIRE(Unserialize(context, "", &axisX));
|
||||
REQUIRE(axisX == copy);
|
||||
}
|
||||
|
||||
|
|
@ -174,11 +174,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Rectf zeroRect = Nz::Rectf::Zero();
|
||||
Nz::Rectf copy(zeroRect);
|
||||
REQUIRE(Serialize(context, zeroRect));
|
||||
REQUIRE(Serialize(context, "", zeroRect));
|
||||
zeroRect = Nz::Rectf(1, 1, 1, 1); // Random values
|
||||
REQUIRE(zeroRect != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroRect));
|
||||
REQUIRE(Unserialize(context, "", &zeroRect));
|
||||
REQUIRE(zeroRect == copy);
|
||||
}
|
||||
|
||||
|
|
@ -187,11 +187,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Spheref zeroSphere = Nz::Spheref::Zero();
|
||||
Nz::Spheref copy(zeroSphere);
|
||||
REQUIRE(Serialize(context, zeroSphere));
|
||||
REQUIRE(Serialize(context, "", zeroSphere));
|
||||
zeroSphere = Nz::Spheref::Unit();
|
||||
REQUIRE(zeroSphere != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &zeroSphere));
|
||||
REQUIRE(Unserialize(context, "", &zeroSphere));
|
||||
REQUIRE(zeroSphere == copy);
|
||||
}
|
||||
|
||||
|
|
@ -200,11 +200,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Vector2f unitX = Nz::Vector2f::UnitX();
|
||||
Nz::Vector2f copy(unitX);
|
||||
REQUIRE(Serialize(context, unitX));
|
||||
REQUIRE(Serialize(context, "", unitX));
|
||||
unitX = Nz::Vector2f::UnitY();
|
||||
REQUIRE(unitX != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &unitX));
|
||||
REQUIRE(Unserialize(context, "", &unitX));
|
||||
REQUIRE(unitX == copy);
|
||||
}
|
||||
|
||||
|
|
@ -213,11 +213,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Vector3f unitX = Nz::Vector3f::UnitX();
|
||||
Nz::Vector3f copy(unitX);
|
||||
REQUIRE(Serialize(context, unitX));
|
||||
REQUIRE(Serialize(context, "", unitX));
|
||||
unitX = Nz::Vector3f::UnitY();
|
||||
REQUIRE(unitX != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &unitX));
|
||||
REQUIRE(Unserialize(context, "", &unitX));
|
||||
REQUIRE(unitX == copy);
|
||||
}
|
||||
|
||||
|
|
@ -226,11 +226,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Vector4f unitX = Nz::Vector4f::UnitX();
|
||||
Nz::Vector4f copy(unitX);
|
||||
REQUIRE(Serialize(context, unitX));
|
||||
REQUIRE(Serialize(context, "", unitX));
|
||||
unitX = Nz::Vector4f::UnitY();
|
||||
REQUIRE(unitX != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &unitX));
|
||||
REQUIRE(Unserialize(context, "", &unitX));
|
||||
REQUIRE(unitX == copy);
|
||||
}
|
||||
}
|
||||
|
|
@ -242,11 +242,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
Nz::Color red = Nz::Color::Red();
|
||||
Nz::Color copy(red);
|
||||
REQUIRE(Serialize(context, red));
|
||||
REQUIRE(Serialize(context, "", red));
|
||||
red = Nz::Color::Black();
|
||||
REQUIRE(red != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &red));
|
||||
REQUIRE(Unserialize(context, "", &red));
|
||||
REQUIRE(red == copy);
|
||||
}
|
||||
|
||||
|
|
@ -255,11 +255,11 @@ SCENARIO("Serialization", "[CORE][SERIALIZATION]")
|
|||
context.stream->SetCursorPos(0);
|
||||
std::string string = "string";
|
||||
std::string copy(string);
|
||||
REQUIRE(Serialize(context, string));
|
||||
REQUIRE(Serialize(context, "", string));
|
||||
string = "another";
|
||||
REQUIRE(string != copy);
|
||||
context.stream->SetCursorPos(0);
|
||||
REQUIRE(Unserialize(context, &string));
|
||||
REQUIRE(Unserialize(context, "", &string));
|
||||
REQUIRE(string == copy);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue