Files
VoidNet/src/Serializer.cpp
xX-TheDoctor-Xx a211400964 Added Development information for me to dont forget things xD
Added AllAndMe DistributionType
Added a ThreadPool class
Added VoidNetClientAPI
2016-07-18 01:13:20 +01:00

23 lines
680 B
C++

#include "Serializer.hpp"
template<typename T> const std::vector<byte> &Serializer::to_bytes(const T& object)
{
std::vector<byte> bytes;
const byte *begin = reinterpret_cast<const byte*>(std::addressof(object));
const byte *end = begin + sizeof(T);
std::copy(begin, end, std::begin(bytes));
return bytes;
}
template<typename T> const 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::vector<byte> bytes_vector(&bytes);
std::copy(bytes_vector.begin(), bytes_vector.end(), begin_object);
return object;
}