WIP: Track version numbers
This commit is contained in:
parent
2c243c3e41
commit
2c6c63579b
|
@ -30,7 +30,7 @@ template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void readCustom
|
||||||
boost::hana::keys(customType), [&deserializer, &customType](auto key) { deserializer.read(boost::hana::at_key(customType, key)); });
|
boost::hana::keys(customType), [&deserializer, &customType](auto key) { deserializer.read(boost::hana::at_key(customType, key)); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void writeCustomType(BinarySerializer &serializer, const Type &customType)
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void writeCustomType(BinarySerializer &serializer, const Type &customType, BinaryVersion version)
|
||||||
{
|
{
|
||||||
boost::hana::for_each(
|
boost::hana::for_each(
|
||||||
boost::hana::keys(customType), [&serializer, &customType](auto key) { serializer.write(boost::hana::at_key(customType, key)); });
|
boost::hana::keys(customType), [&serializer, &customType](auto key) { serializer.write(boost::hana::at_key(customType, key)); });
|
||||||
|
|
|
@ -33,7 +33,9 @@ template <typename T> struct AdaptedBinarySerializable : public Traits::Bool<fal
|
||||||
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::AdaptedBinarySerializable";
|
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::AdaptedBinarySerializable";
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Type> struct BinarySerializable;
|
using BinaryVersion = std::uint64_t;
|
||||||
|
|
||||||
|
template <typename Type, BinaryVersion defaultVersion = 0> struct BinarySerializable;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief The BinaryReflector namespace contains BinaryReader and BinaryWriter for automatic binary (de)serialization.
|
* \brief The BinaryReflector namespace contains BinaryReader and BinaryWriter for automatic binary (de)serialization.
|
||||||
|
@ -51,7 +53,7 @@ class BinaryDeserializer;
|
||||||
class BinarySerializer;
|
class BinarySerializer;
|
||||||
|
|
||||||
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void readCustomType(BinaryDeserializer &deserializer, Type &customType);
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void readCustomType(BinaryDeserializer &deserializer, Type &customType);
|
||||||
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void writeCustomType(BinarySerializer &serializer, const Type &customType);
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void writeCustomType(BinarySerializer &serializer, const Type &customType, BinaryVersion version = 0);
|
||||||
|
|
||||||
class BinaryDeserializer : public CppUtilities::BinaryReader {
|
class BinaryDeserializer : public CppUtilities::BinaryReader {
|
||||||
friend class ::BinaryReflectorTests;
|
friend class ::BinaryReflectorTests;
|
||||||
|
@ -90,7 +92,7 @@ public:
|
||||||
template <typename Type, Traits::EnableIf<IsIteratableExceptString<Type>, Traits::HasSize<Type>> * = nullptr> void write(const Type &iteratable);
|
template <typename Type, Traits::EnableIf<IsIteratableExceptString<Type>, Traits::HasSize<Type>> * = nullptr> void write(const Type &iteratable);
|
||||||
template <typename Type, Traits::EnableIf<std::is_enum<Type>> * = nullptr> void write(const Type &enumValue);
|
template <typename Type, Traits::EnableIf<std::is_enum<Type>> * = nullptr> void write(const Type &enumValue);
|
||||||
template <typename Type, Traits::EnableIf<IsVariant<Type>> * = nullptr> void write(const Type &variant);
|
template <typename Type, Traits::EnableIf<IsVariant<Type>> * = nullptr> void write(const Type &variant);
|
||||||
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void write(const Type &customType);
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void write(const Type &customType, BinaryVersion version = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::uint64_t, bool> m_pointer;
|
std::unordered_map<std::uint64_t, bool> m_pointer;
|
||||||
|
@ -286,9 +288,9 @@ template <typename Type, Traits::EnableIf<IsVariant<Type>> *> void BinarySeriali
|
||||||
variant);
|
variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void BinarySerializer::write(const Type &customType)
|
template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void BinarySerializer::write(const Type &customType, BinaryVersion version)
|
||||||
{
|
{
|
||||||
writeCustomType(*this, customType);
|
writeCustomType(*this, customType, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace BinaryReflector
|
} // namespace BinaryReflector
|
||||||
|
|
|
@ -17,25 +17,26 @@ namespace ReflectiveRapidJSON {
|
||||||
/*!
|
/*!
|
||||||
* \brief The BinarySerializable class provides the CRTP-base for (de)serializable objects.
|
* \brief The BinarySerializable class provides the CRTP-base for (de)serializable objects.
|
||||||
*/
|
*/
|
||||||
template <typename Type> struct BinarySerializable {
|
template <typename Type, BinaryVersion defaultVersion> struct BinarySerializable {
|
||||||
void toBinary(std::ostream &outputStream) const;
|
void toBinary(std::ostream &outputStream) const;
|
||||||
void restoreFromBinary(std::istream &inputStream);
|
void restoreFromBinary(std::istream &inputStream);
|
||||||
static Type fromBinary(std::istream &inputStream);
|
static Type fromBinary(std::istream &inputStream);
|
||||||
|
|
||||||
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
|
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
|
||||||
|
static constexpr auto defaultSerializeVersion = defaultVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Type> inline void BinarySerializable<Type>::toBinary(std::ostream &outputStream) const
|
template <typename Type, BinaryVersion defaultVersion> inline void BinarySerializable<Type, defaultVersion>::toBinary(std::ostream &outputStream) const
|
||||||
{
|
{
|
||||||
BinaryReflector::BinarySerializer(&outputStream).write(static_cast<const Type &>(*this));
|
BinaryReflector::BinarySerializer(&outputStream).write(static_cast<const Type &>(*this), defaultVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type> inline void BinarySerializable<Type>::restoreFromBinary(std::istream &inputStream)
|
template <typename Type, BinaryVersion defaultVersion> inline void BinarySerializable<Type, defaultVersion>::restoreFromBinary(std::istream &inputStream)
|
||||||
{
|
{
|
||||||
BinaryReflector::BinaryDeserializer(&inputStream).read(static_cast<Type &>(*this));
|
BinaryReflector::BinaryDeserializer(&inputStream).read(static_cast<Type &>(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type> Type BinarySerializable<Type>::fromBinary(std::istream &inputStream)
|
template <typename Type, BinaryVersion defaultVersion> Type BinarySerializable<Type, defaultVersion>::fromBinary(std::istream &inputStream)
|
||||||
{
|
{
|
||||||
Type object;
|
Type object;
|
||||||
static_cast<BinarySerializable<Type> &>(object).restoreFromBinary(inputStream);
|
static_cast<BinarySerializable<Type> &>(object).restoreFromBinary(inputStream);
|
||||||
|
|
Loading…
Reference in New Issue