Rename functions of BinarySerializable
So the names are more like the ones in JsonSerializable.
This commit is contained in:
parent
04dccdbd74
commit
6117ef3e1d
|
@ -18,22 +18,31 @@ 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> struct BinarySerializable {
|
||||||
void serialize(std::ostream &outputStream) const;
|
void toBinary(std::ostream &outputStream) const;
|
||||||
void deserialize(std::istream &inputStream);
|
void restoreFromBinary(std::istream &inputStream);
|
||||||
|
static Type fromBinary(std::istream &inputStream);
|
||||||
|
|
||||||
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
|
static constexpr const char *qualifiedName = "ReflectiveRapidJSON::BinarySerializable";
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Type> inline void BinarySerializable<Type>::serialize(std::ostream &outputStream) const
|
template <typename Type> inline void BinarySerializable<Type>::toBinary(std::ostream &outputStream) const
|
||||||
{
|
{
|
||||||
BinaryReflector::BinarySerializer(&outputStream).write(static_cast<const Type &>(*this));
|
BinaryReflector::BinarySerializer(&outputStream).write(static_cast<const Type &>(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Type> inline void BinarySerializable<Type>::deserialize(std::istream &inputStream)
|
template <typename Type> inline void BinarySerializable<Type>::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)
|
||||||
|
{
|
||||||
|
Type object;
|
||||||
|
static_cast<BinarySerializable<Type> &>(object).restoreFromBinary(inputStream);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \def The REFLECTIVE_RAPIDJSON_MAKE_BINARY_SERIALIZABLE macro allows to adapt (de)serialization for types defined in 3rd party header files.
|
* \def The REFLECTIVE_RAPIDJSON_MAKE_BINARY_SERIALIZABLE macro allows to adapt (de)serialization for types defined in 3rd party header files.
|
||||||
* \remarks The struct will not have the toBinary() and fromBinary() methods available. Use the corresponding functions in the namespace
|
* \remarks The struct will not have the toBinary() and fromBinary() methods available. Use the corresponding functions in the namespace
|
||||||
|
|
|
@ -83,12 +83,10 @@ void BinaryReflectorBoostHanaTests::testSerializingAndDeserializing()
|
||||||
|
|
||||||
stringstream stream(ios_base::in | ios_base::out | ios_base::binary);
|
stringstream stream(ios_base::in | ios_base::out | ios_base::binary);
|
||||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
nestingObject.serialize(stream);
|
nestingObject.toBinary(stream);
|
||||||
|
|
||||||
NestingArrayBinaryHana deserializedObject;
|
|
||||||
deserializedObject.deserialize(stream);
|
|
||||||
const TestObjectBinaryHana &deserializedTestObj(deserializedObject.testObjects.at(0));
|
|
||||||
|
|
||||||
|
const auto deserializedObject(NestingArrayBinaryHana::fromBinary(stream));
|
||||||
|
const auto &deserializedTestObj(deserializedObject.testObjects.at(0));
|
||||||
CPPUNIT_ASSERT_EQUAL(nestingObject.name, deserializedObject.name);
|
CPPUNIT_ASSERT_EQUAL(nestingObject.name, deserializedObject.name);
|
||||||
CPPUNIT_ASSERT_EQUAL(testObject.number, deserializedTestObj.number);
|
CPPUNIT_ASSERT_EQUAL(testObject.number, deserializedTestObj.number);
|
||||||
CPPUNIT_ASSERT_EQUAL(testObject.number2, deserializedTestObj.number2);
|
CPPUNIT_ASSERT_EQUAL(testObject.number2, deserializedTestObj.number2);
|
||||||
|
|
|
@ -240,7 +240,7 @@ void BinaryReflectorTests::testSerializeSimpleStruct()
|
||||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
m_buffer.resize(m_expectedTestObj.size());
|
m_buffer.resize(m_expectedTestObj.size());
|
||||||
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_buffer.data()), static_cast<streamsize>(m_buffer.size()));
|
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_buffer.data()), static_cast<streamsize>(m_buffer.size()));
|
||||||
m_testObj.serialize(stream);
|
m_testObj.toBinary(stream);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(m_expectedTestObj, m_buffer);
|
CPPUNIT_ASSERT_EQUAL(m_expectedTestObj, m_buffer);
|
||||||
}
|
}
|
||||||
|
@ -250,8 +250,7 @@ void BinaryReflectorTests::testDeserializeSimpleStruct()
|
||||||
stringstream stream(ios_base::in | ios_base::binary);
|
stringstream stream(ios_base::in | ios_base::binary);
|
||||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_expectedTestObj.data()), static_cast<streamsize>(m_expectedTestObj.size()));
|
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_expectedTestObj.data()), static_cast<streamsize>(m_expectedTestObj.size()));
|
||||||
TestObjectBinary deserialized;
|
const auto deserialized(TestObjectBinary::fromBinary(stream));
|
||||||
deserialized.deserialize(stream);
|
|
||||||
assertTestObject(deserialized);
|
assertTestObject(deserialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +260,7 @@ void BinaryReflectorTests::testSerializeNestedStruct()
|
||||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
m_buffer.resize(m_expectedNestedTestObj.size());
|
m_buffer.resize(m_expectedNestedTestObj.size());
|
||||||
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_buffer.data()), static_cast<streamsize>(m_buffer.size()));
|
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_buffer.data()), static_cast<streamsize>(m_buffer.size()));
|
||||||
m_nestedTestObj.serialize(stream);
|
m_nestedTestObj.toBinary(stream);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(m_expectedNestedTestObj, m_buffer);
|
CPPUNIT_ASSERT_EQUAL(m_expectedNestedTestObj, m_buffer);
|
||||||
}
|
}
|
||||||
|
@ -271,9 +270,8 @@ void BinaryReflectorTests::testDeserializeNestedStruct()
|
||||||
stringstream stream(ios_base::in | ios_base::binary);
|
stringstream stream(ios_base::in | ios_base::binary);
|
||||||
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
stream.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_expectedNestedTestObj.data()), static_cast<streamsize>(m_expectedNestedTestObj.size()));
|
stream.rdbuf()->pubsetbuf(reinterpret_cast<char *>(m_expectedNestedTestObj.data()), static_cast<streamsize>(m_expectedNestedTestObj.size()));
|
||||||
NestingArrayBinary deserialized;
|
|
||||||
deserialized.deserialize(stream);
|
|
||||||
|
|
||||||
|
const auto deserialized(NestingArrayBinary::fromBinary(stream));
|
||||||
CPPUNIT_ASSERT_EQUAL(m_nestedTestObj.name, deserialized.name);
|
CPPUNIT_ASSERT_EQUAL(m_nestedTestObj.name, deserialized.name);
|
||||||
for (const auto &testObj : deserialized.testObjects) {
|
for (const auto &testObj : deserialized.testObjects) {
|
||||||
assertTestObject(testObj);
|
assertTestObject(testObj);
|
||||||
|
|
Loading…
Reference in New Issue