diff --git a/mc_buffer.cpp b/mc_buffer.cpp index 4fe7014..c9458e0 100644 --- a/mc_buffer.cpp +++ b/mc_buffer.cpp @@ -99,10 +99,9 @@ int Buffer::bytes() const { return m_data.size(); } -bool Buffer::serialize(Serializer* serializer) const { +void Buffer::serialize(Serializer* serializer) const { serializer->write(bytes()); serializer->writeRaw(data(), bytes()); - return true; } bool Buffer::deserialize(Deserializer* deserializer) { diff --git a/mc_buffer.hpp b/mc_buffer.hpp index 7a7e818..243e70d 100644 --- a/mc_buffer.hpp +++ b/mc_buffer.hpp @@ -48,7 +48,7 @@ public: void* data(); int bytes() const; - bool serialize(Serializer* serializer) const; + void serialize(Serializer* serializer) const; bool deserialize(Deserializer* deserializer); private: diff --git a/mc_meta.hpp b/mc_meta.hpp index 15612ba..af27db1 100644 --- a/mc_meta.hpp +++ b/mc_meta.hpp @@ -32,37 +32,9 @@ namespace metacall { // Meta // -qword serialize(Serializer*, ...); - template -struct HasGlobalSerializer { - enum { - Value = sizeof(bool) == sizeof( - serialize( - static_cast(NULL), - *static_cast(NULL) - ) - ) - }; -}; - -qword deserialize(Deserializer*, ...); - -template -struct HasGlobalDeserializer { - enum { - Value = sizeof(bool) == sizeof( - deserialize( - static_cast(NULL), - static_cast(NULL) - ) - ) - }; -}; - -template -struct HasLocalSerializer { - template +struct HasSerializer { + template struct Signature { }; template @@ -77,7 +49,7 @@ struct HasLocalSerializer { }; template -struct HasLocalDeserializer { +struct HasDeserializer { template struct Signature { }; diff --git a/mc_packet.hpp b/mc_packet.hpp index 19ad4f8..8e88605 100644 --- a/mc_packet.hpp +++ b/mc_packet.hpp @@ -55,11 +55,10 @@ struct PacketHeader { { } - bool serialize(Serializer* serializer) const { - return - serializer->write(magic) && - serializer->write(id) && - serializer->write(size); + void serialize(Serializer* serializer) const { + serializer->write(magic); + serializer->write(id); + serializer->write(size); } bool deserialize(Deserializer* deserializer) { @@ -90,11 +89,10 @@ struct PacketInvokeRequest { Id = PACKET_ID_FUNCTION_CALL_REQUEST }; - bool serialize(Serializer* serializer) const { - return - serializer->write(function) && - serializer->write(taskId) && - serializer->write(data); + void serialize(Serializer* serializer) const { + serializer->write(function); + serializer->write(taskId); + serializer->write(data); } bool deserialize(Deserializer* deserializer) { @@ -130,11 +128,10 @@ struct PacketInvokeReply { FLAG_INVALID_ARGS = 1 << 1 }; - bool serialize(Serializer* serializer) const { - return - serializer->write(flags) && - serializer->write(taskId) && - serializer->write(data); + void serialize(Serializer* serializer) const { + serializer->write(flags); + serializer->write(taskId); + serializer->write(data); } bool deserialize(Deserializer* deserializer) { diff --git a/mc_prefab-inl.hpp b/mc_prefab-inl.hpp index 54a2ad1..154b127 100644 --- a/mc_prefab-inl.hpp +++ b/mc_prefab-inl.hpp @@ -31,8 +31,8 @@ namespace metacall { // template -bool serialize(Serializer* serializer, const std::basic_string& value) { - return serialize(serializer, value.c_str()); +void serialize(Serializer* serializer, const std::basic_string& value) { + serialize(serializer, value.c_str()); } template @@ -57,13 +57,12 @@ bool deserialize(Deserializer* deserializer, std::basic_string* value) // template -bool serialize(Serializer* serializer, const std::vector& value) { +void serialize(Serializer* serializer, const std::vector& value) { serializer->write(value.size()); for (const typename std::vector::const_iterator iter = value.begin(); iter != value.end(); ++iter) { serializer->write(*iter); } - return true; } template @@ -93,13 +92,11 @@ bool deserialize(Deserializer* deserializer, std::vector* value) { // template -bool serialize(Serializer* serializer, const std::list& value) { +void serialize(Serializer* serializer, const std::list& value) { serializer->write(value.size()); for (const typename std::list::const_iterator iter = value.begin(); iter != value.end(); ++iter) { serializer->write(*iter); } - - return true; } template @@ -129,7 +126,7 @@ bool deserialize(Deserializer* deserializer, std::list* value) { // template -bool serialize(Serializer* serializer, const std::pair& value) { +void serialize(Serializer* serializer, const std::pair& value) { serializer->write(value.first); serializer->write(value.second); return true; @@ -146,13 +143,11 @@ bool deserialize(Deserializer* deserializer, std::pair* value) { // template -bool serialize(Serializer* serializer, const std::map& value) { +void serialize(Serializer* serializer, const std::map& value) { serializer->write(value.size()); for (const typename std::map::const_iterator iter = value.begin(); iter != value.end(); ++iter) { serializer->write(*iter); } - - return true; } template diff --git a/mc_prefab.cpp b/mc_prefab.cpp index d0db252..ff4f982 100644 --- a/mc_prefab.cpp +++ b/mc_prefab.cpp @@ -41,11 +41,10 @@ static int strLen(const wchar_t str[]) { } template -static bool serializeStr(Serializer* serializer, const T value[]) { +static void serializeStr(Serializer* serializer, const T value[]) { const int length = value == NULL ? 0 : strLen(value) + 1; serializer->write(length); serializer->writeRaw(value, length * sizeof(T)); - return true; } template @@ -70,16 +69,16 @@ static bool deserializeStr(Deserializer* deserializer, const T ** value) { // C strings // -bool serialize(Serializer* serializer, const char value[]) { - return serializeStr(serializer, value); +void serialize(Serializer* serializer, const char value[]) { + serializeStr(serializer, value); } bool deserialize(Deserializer* deserializer, const char ** value) { return deserializeStr(deserializer, value); } -bool serialize(Serializer* serializer, const wchar_t value[]) { - return serializeStr(serializer, value); +void serialize(Serializer* serializer, const wchar_t value[]) { + serializeStr(serializer, value); } bool deserialize(Deserializer* deserializer, const wchar_t ** value) { diff --git a/mc_prefab.hpp b/mc_prefab.hpp index 8039acc..8a3499e 100644 --- a/mc_prefab.hpp +++ b/mc_prefab.hpp @@ -32,9 +32,9 @@ namespace metacall { // C string // -bool serialize(Serializer* serializer, const char value[]); +void serialize(Serializer* serializer, const char value[]); bool deserialize(Deserializer* deserializer, const char ** value); -bool serialize(Serializer* serializer, const wchar_t value[]); +void serialize(Serializer* serializer, const wchar_t value[]); bool deserialize(Deserializer* deserializer, const wchar_t ** value); @@ -43,7 +43,7 @@ bool deserialize(Deserializer* deserializer, const wchar_t ** value); // template -bool serialize(Serializer* serializer, const std::basic_string& value); +void serialize(Serializer* serializer, const std::basic_string& value); template bool deserialize(Deserializer* deserializer, std::basic_string* value); @@ -53,7 +53,7 @@ bool deserialize(Deserializer* deserializer, std::basic_string* value); // template -bool serialize(Serializer* serializer, const std::vector& value); +void serialize(Serializer* serializer, const std::vector& value); template bool deserialize(Deserializer* deserializer, std::vector* value); @@ -63,7 +63,7 @@ bool deserialize(Deserializer* deserializer, std::vector* value); // template -bool serialize(Serializer* serializer, const std::list& value); +void serialize(Serializer* serializer, const std::list& value); template bool deserialize(Deserializer* deserializer, std::list* value); @@ -73,7 +73,7 @@ bool deserialize(Deserializer* deserializer, std::list* value); // template -bool serialize(Serializer* serializer, const std::pair& value); +void serialize(Serializer* serializer, const std::pair& value); template bool deserialize(Deserializer* deserializer, std::pair* value); @@ -83,7 +83,7 @@ bool deserialize(Deserializer* deserializer, std::pair* value); // template -bool serialize(Serializer* serializer, const std::map& value); +void serialize(Serializer* serializer, const std::map& value); template bool deserialize(Deserializer* deserializer, std::map* value); diff --git a/mc_serial-inl.hpp b/mc_serial-inl.hpp index 7772e7c..2f95433 100644 --- a/mc_serial-inl.hpp +++ b/mc_serial-inl.hpp @@ -30,7 +30,7 @@ namespace metacall { // TypeReader // -template +template struct TypeReader { static bool read(Deserializer* deserializer, T* data) { return data->deserialize(deserializer); @@ -38,14 +38,7 @@ struct TypeReader { }; template -struct TypeReader { - static bool read(Deserializer* deserializer, T* data) { - return deserialize(deserializer, data); - } -}; - -template -struct TypeReader { +struct TypeReader { static bool read(Deserializer* deserializer, T* data) { const T* const temp = reinterpret_cast( deserializer->readRaw(sizeof(T)) @@ -61,11 +54,7 @@ struct TypeReader { template bool Deserializer::read(T* data) { - return TypeReader< - T, - HasLocalDeserializer::Value, - HasGlobalDeserializer::Value - >::read(this, data); + return deserialize(this, data); } @@ -73,34 +62,38 @@ bool Deserializer::read(T* data) { // TypeWriter // -template +template struct TypeWriter { - static bool write(Serializer* serializer, const T& data) { - return data.serialize(serializer); + static void write(Serializer* serializer, const T& data) { + data.serialize(serializer); } }; template -struct TypeWriter { - static bool write(Serializer* serializer, const T& data) { - return serialize(serializer, data); +struct TypeWriter { + static void write(Serializer* serializer, const T& data) { + serializer->writeRaw(&data, sizeof(T)); } }; template -struct TypeWriter { - static bool write(Serializer* serializer, const T& data) { - return serializer->writeRaw(&data, sizeof(T)); - } -}; +void Serializer::write(const T& data) { + serialize(this, data); +} + + +// +// Handlers +// template -bool Serializer::write(const T& data) { - return TypeWriter< - T, - HasLocalSerializer::Value, - HasGlobalSerializer::Value - >::write(this, data); +void serialize(Serializer* serializer, const T& data) { + TypeWriter::Value>::write(serializer, data); +} + +template +bool deserialize(Deserializer* deserializer, T* data) { + return TypeReader::Value>::read(deserializer, data); } diff --git a/mc_serial.cpp b/mc_serial.cpp index 9c2a243..9611b6d 100644 --- a/mc_serial.cpp +++ b/mc_serial.cpp @@ -75,13 +75,11 @@ Serializer::Serializer(Buffer* data) : { } -bool Serializer::writeRaw(const void* data, int size) { +void Serializer::writeRaw(const void* data, int size) { if (m_data != NULL) { m_data->addToBack(static_cast(data), size); m_offset += size; } - - return true; } bool Serializer::setOffset(int offset, bool relative) { diff --git a/mc_serial.hpp b/mc_serial.hpp index 366320f..8e0d339 100644 --- a/mc_serial.hpp +++ b/mc_serial.hpp @@ -57,8 +57,8 @@ public: Serializer(Buffer* data); template - bool write(const T& data); - bool writeRaw(const void* data, int size); + void write(const T& data); + void writeRaw(const void* data, int size); bool setOffset(int offset, bool relative); int offset() const; @@ -68,4 +68,15 @@ private: }; +// +// Handlers +// + +template +void serialize(Serializer* serializer, const T& data); + +template +bool deserialize(Deserializer* deserializer, T* data); + + }