WIP: Allow specifying version of binary serializable

This commit is contained in:
Martchus 2021-05-23 18:20:17 +02:00
parent cb98e348f1
commit 3f6f790849
2 changed files with 13 additions and 0 deletions

View File

@ -35,6 +35,10 @@ template <typename T> struct AdaptedBinarySerializable : public Traits::Bool<fal
template <typename Type> struct BinarySerializable;
template <typename Type> struct BinarySerializableMeta {
static constexpr std::uint64_t version = 0;
};
/*!
* \brief The BinaryReflector namespace contains BinaryReader and BinaryWriter for automatic binary (de)serialization.
*/

View File

@ -23,6 +23,7 @@ template <typename Type> struct BinarySerializable {
static Type fromBinary(std::istream &inputStream);
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
static constexpr auto version = BinarySerializableMeta<Type>::version;
};
template <typename Type> inline void BinarySerializable<Type>::toBinary(std::ostream &outputStream) const
@ -53,6 +54,14 @@ template <typename Type> Type BinarySerializable<Type>::fromBinary(std::istream
template <> struct ReflectiveRapidJSON::AdaptedBinarySerializable<T> : Traits::Bool<true> { \
}
/*!
* \def The REFLECTIVE_RAPIDJSON_DECLARE_BINARY_SERIALIZABLE_VERSION macro allows to declare the version of a BinarySerializable.
*/
#define REFLECTIVE_RAPIDJSON_DECLARE_BINARY_SERIALIZABLE_VERSION(T, v) \
template <> struct ReflectiveRapidJSON::BinarySerializableMeta<T> { \
static constexpr std::uint64_t version = v; \
}
} // namespace ReflectiveRapidJSON
#endif // REFLECTIVE_RAPIDJSON_BINARY_SERIALIZABLE_H