#pragma once #include "ArchiveBuffer.h" #include "Math/Vector.h" namespace Seele { namespace Serialization { template static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); } template static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); } template static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); } template static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); } static void save(ArchiveBuffer& buffer, const IVector2& vec) { save(buffer, vec.x); save(buffer, vec.y); } static void load(ArchiveBuffer& buffer, IVector2& vec) { load(buffer, vec.x); load(buffer, vec.y); } static void save(ArchiveBuffer& buffer, const Vector2& vec) { save(buffer, vec.x); save(buffer, vec.y); } static void load(ArchiveBuffer& buffer, Vector2& vec) { load(buffer, vec.x); load(buffer, vec.y); } static void save(ArchiveBuffer& buffer, const Vector& vec) { save(buffer, vec.x); save(buffer, vec.y); save(buffer, vec.z); } static void load(ArchiveBuffer& buffer, Vector& vec) { load(buffer, vec.x); load(buffer, vec.y); load(buffer, vec.z); } template static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); } template static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); } template static void save(ArchiveBuffer& buffer, const T& type) requires(serializable) { type.save(buffer); } template static void load(ArchiveBuffer& buffer, T& type) requires(serializable) { type.load(buffer); } template static void save(ArchiveBuffer& buffer, const OwningPtr& ptr); template static void load(ArchiveBuffer& buffer, OwningPtr& ptr); static void save(ArchiveBuffer& buffer, const std::string& type) { uint64 length = type.size(); buffer.writeBytes(&length, sizeof(uint64)); buffer.writeBytes(type.data(), type.size() * sizeof(char)); } static void load(ArchiveBuffer& buffer, std::string& type) { uint64 length = 0; buffer.readBytes(&length, sizeof(uint64)); type.resize(length); buffer.readBytes(type.data(), length * sizeof(char)); } template static void save(ArchiveBuffer& buffer, const Array& type) requires (std::is_trivially_copyable_v) { uint64 length = type.size(); buffer.writeBytes(&length, sizeof(uint64)); buffer.writeBytes(type.data(), sizeof(T) * type.size()); } template static void load(ArchiveBuffer& buffer, Array& type) requires (std::is_trivially_copyable_v) { uint64 length = 0; buffer.readBytes(&length, sizeof(uint64)); type.resize(length); buffer.readBytes(type.data(), sizeof(T) * type.size()); } template static void save(ArchiveBuffer& buffer, const StaticArray& type) requires (std::is_trivially_copyable_v) { buffer.writeBytes(type.data(), sizeof(T) * N); } template static void load(ArchiveBuffer& buffer, StaticArray& type) requires (std::is_trivially_copyable_v) { buffer.readBytes(type.data(), sizeof(T) * N); } template static void save(ArchiveBuffer& buffer, const Array& type) { uint64 length = type.size(); buffer.writeBytes(&length, sizeof(uint64)); for (const T& x : type) { save(buffer, x); } } template static void load(ArchiveBuffer& buffer, Array& type) { uint64 length = 0; buffer.readBytes(&length, sizeof(uint64)); type.reserve(length); for (uint32 i = 0; i < length; ++i) { T t = T(); load(buffer, t); type.add(std::move(t)); } } } // namespace Serialization } // namespace Seele