serialization: Rename SerializerBinary to BinarySerializer

This commit is contained in:
Joshua Scott 2018-12-14 15:27:06 +00:00
parent 187de3feba
commit 20f74ee004
6 changed files with 28 additions and 28 deletions

View File

@ -13,7 +13,7 @@ namespace serialization
/**
* TODO: Documentation
*/
class SerializerBinary
class BinarySerializer
{
public:
/**
@ -41,9 +41,9 @@ namespace serialization
* @param is_file Determines whether or not to write type sizes, and property headers.
* @param flags Determines how serialized data is formatted.
*/
explicit SerializerBinary(const pclass::TypeSystem &type_system,
explicit BinarySerializer(const pclass::TypeSystem &type_system,
bool is_file, flags flags);
virtual ~SerializerBinary() {}
virtual ~BinarySerializer() {}
/**
* @param object
@ -110,4 +110,4 @@ namespace serialization
}
// Make sure the flags enum can be used like a bitflag
MAKE_FLAGS_ENUM(ki::serialization::SerializerBinary::flags);
MAKE_FLAGS_ENUM(ki::serialization::BinarySerializer::flags);

View File

@ -1,4 +1,4 @@
#include "ki/serialization/SerializerBinary.h"
#include "ki/serialization/BinarySerializer.h"
#include <zlib.h>
#include <cassert>
#include "ki/util/unique.h"
@ -7,7 +7,7 @@ namespace ki
{
namespace serialization
{
SerializerBinary::SerializerBinary(const pclass::TypeSystem &type_system,
BinarySerializer::BinarySerializer(const pclass::TypeSystem &type_system,
const bool is_file, const flags flags)
{
m_type_system = &type_system;
@ -16,7 +16,7 @@ namespace serialization
m_root_object = nullptr;
}
void SerializerBinary::save(const pclass::PropertyClass *object, BitStream &stream)
void BinarySerializer::save(const pclass::PropertyClass *object, BitStream &stream)
{
// Write the serializer flags
if (FLAG_IS_SET(m_flags, flags::WRITE_SERIALIZER_FLAGS))
@ -114,7 +114,7 @@ namespace serialization
}
}
void SerializerBinary::presave_object(const pclass::PropertyClass *object, BitStream &stream) const
void BinarySerializer::presave_object(const pclass::PropertyClass *object, BitStream &stream) const
{
// If we have an object, write the type hash, otherwise, write NULL (0).
if (object)
@ -123,7 +123,7 @@ namespace serialization
stream.write<uint32_t>(NULL);
}
void SerializerBinary::save_object(const pclass::PropertyClass *object, BitStream &stream) const
void BinarySerializer::save_object(const pclass::PropertyClass *object, BitStream &stream) const
{
// Write any object headers
presave_object(object, stream);
@ -165,7 +165,7 @@ namespace serialization
stream.seek(BitStream::stream_pos(stream.tell().as_bytes(), 0));
}
void SerializerBinary::save_property(const pclass::IProperty &prop, BitStream &stream) const
void BinarySerializer::save_property(const pclass::IProperty &prop, BitStream &stream) const
{
// Remember where we started writing the property data
const auto start_pos = stream.tell();
@ -236,7 +236,7 @@ namespace serialization
}
}
void SerializerBinary::load(
void BinarySerializer::load(
std::unique_ptr<pclass::PropertyClass> &dest,
BitStream &stream, const std::size_t size)
{
@ -299,7 +299,7 @@ namespace serialization
load_object(dest, segment_stream);
}
void SerializerBinary::preload_object(
void BinarySerializer::preload_object(
std::unique_ptr<pclass::PropertyClass> &dest, BitStream &stream) const
{
const auto type_hash = stream.read<pclass::hash_t>();
@ -314,7 +314,7 @@ namespace serialization
dest = nullptr;
}
void SerializerBinary::load_object(
void BinarySerializer::load_object(
std::unique_ptr<pclass::PropertyClass> &dest, BitStream &stream) const
{
// Read the object header
@ -376,7 +376,7 @@ namespace serialization
stream.seek(BitStream::stream_pos(stream.tell().as_bytes(), 0), false);
}
void SerializerBinary::load_property(pclass::IProperty &prop, BitStream &stream) const
void BinarySerializer::load_property(pclass::IProperty &prop, BitStream &stream) const
{
auto &property_type = prop.get_type();
if (prop.is_dynamic())

View File

@ -1,4 +1,4 @@
target_sources(${PROJECT_NAME}
PRIVATE
${PROJECT_SOURCE_DIR}/src/serialization/SerializerBinary.cpp
${PROJECT_SOURCE_DIR}/src/serialization/BinarySerializer.cpp
)

View File

@ -7,7 +7,7 @@
#include <ki/pclass/PropertyClass.h>
#include <ki/pclass/StaticProperty.h>
#include <ki/pclass/VectorProperty.h>
#include <ki/serialization/SerializerBinary.h>
#include <ki/serialization/BinarySerializer.h>
#include "ki/util/unique.h"
using namespace ki;
@ -394,11 +394,11 @@ void validate_test_object(TestObject &object)
}
/**
* Conduct save/load tests with a SerializerBinary instance.
* Conduct save/load tests with a BinarySerializer instance.
*/
void test_serializer(
std::unique_ptr<TestObject> &test_object,
serialization::SerializerBinary &serializer,
serialization::BinarySerializer &serializer,
const std::string &file_suffix)
{
BitBuffer buffer;
@ -473,38 +473,38 @@ TEST_CASE("Serialization tests", "[serialization]")
std::unique_ptr<TestObject> test_object = nullptr;
define_types();
SECTION("SerializerBinary")
SECTION("BinarySerializer")
{
SECTION("Regular format without compression")
{
serialization::SerializerBinary serializer(
serialization::BinarySerializer serializer(
*g_type_system.get(), false,
serialization::SerializerBinary::flags::NONE
serialization::BinarySerializer::flags::NONE
);
test_serializer(test_object, serializer, "_regular");
}
SECTION("File format without compression")
{
serialization::SerializerBinary serializer(
serialization::BinarySerializer serializer(
*g_type_system.get(), true,
serialization::SerializerBinary::flags::WRITE_SERIALIZER_FLAGS
serialization::BinarySerializer::flags::WRITE_SERIALIZER_FLAGS
);
test_serializer(test_object, serializer, "_file");
}
SECTION("Regular format with compression")
{
serialization::SerializerBinary serializer(
serialization::BinarySerializer serializer(
*g_type_system.get(), false,
serialization::SerializerBinary::flags::COMPRESSED
serialization::BinarySerializer::flags::COMPRESSED
);
test_serializer(test_object, serializer, "_regular_compressed");
}
SECTION("File format with compression")
{
serialization::SerializerBinary serializer(
serialization::BinarySerializer serializer(
*g_type_system.get(), true,
serialization::SerializerBinary::flags::WRITE_SERIALIZER_FLAGS |
serialization::SerializerBinary::flags::COMPRESSED
serialization::BinarySerializer::flags::WRITE_SERIALIZER_FLAGS |
serialization::BinarySerializer::flags::COMPRESSED
);
test_serializer(test_object, serializer, "_file_compressed");
}