Got tcp receiving for windows done

Callbacks are done - maybe ill add a few more later - i dont know if they will work correctly yet
Fixed the Serialization class
Added internal tags - for now it only has CONNECT and DISCONNECT - maybe ill add more later
Fixed some data type parameters in some functions
This commit is contained in:
xX-TheDoctor-Xx
2016-07-17 19:59:22 +01:00
parent 16ed3619b3
commit 72aa8ee0c4
11 changed files with 56 additions and 22 deletions

View File

@ -1,8 +1,10 @@
#include "Serializer.hpp"
template<typename T> std::array<byte, sizeof(T)> Serializer::to_bytes(const T& object)
#include <vector>
template<typename T> const std::vector<byte> &Serializer::to_bytes(const T& object)
{
std::array<byte, sizeof(T)> bytes;
std::vector<byte> bytes;
const byte *begin = reinterpret_cast<const byte*>(std::addressof(object));
const byte *end = begin + sizeof(T);
@ -11,12 +13,13 @@ template<typename T> std::array<byte, sizeof(T)> Serializer::to_bytes(const T& o
return bytes;
}
template<typename T> T& Serializer::from_bytes(const std::array<byte, sizeof(T)> &bytes, T& object)
template<typename T> T& Serializer::from_bytes(byte *bytes, T& object)
{
static_assert(std::is_trivially_copyable<T>::value, "not a TriviallyCopyable type");
byte *begin_object = reinterpret_cast<byte*>(std::addressof(object));
std::copy(std::begin(bytes), std::end(bytes), begin_object);
std::vector<byte> bytes_vector(&bytes);
std::copy(bytes_vector.begin(), bytes_vector.end(), begin_object);
return object;
}