8 #ifndef SERIALIZATION_HPP_
9 #define SERIALIZATION_HPP_
45 NUMBER_PLAYERS_IN_LOBBY,
76 using byte =
unsigned char;
83 template <
class Serializable>
91 static std::vector<byte>
serialize(Serializable
const &obj) {
92 std::vector<byte> ret;
94 ret.resize(
sizeof(Serializable));
95 std::memcpy(ret.data(), std::addressof(obj),
sizeof(Serializable));
108 std::memcpy(&s, v.data(),
sizeof(Serializable));
125 template<
class Seriazable>
128 std::vector<byte> bytes;
129 bytes.resize(
sizeof(uint8_t));
131 std::memcpy(bytes.data(), &
id,
sizeof(uint8_t));
133 bytes.insert(bytes.end(), data.begin(), data.end());
143 static uint8_t
getId(std::vector<byte>
const &bytes)
146 std::memcpy(&
id, bytes.data(),
sizeof(uint8_t));
A templated class to serialize and unserialize a packet (as a std::vector of bytes)
Definition: Serialization.hpp:84
Enum representing Type of request sent from Client to Network.
Definition: Serialization.hpp:20
static Serializable unserialize(std::vector< byte > const &v)
A method to unserialize a vector of byte into an object (passed as template argument)
Definition: Serialization.hpp:105
static std::vector< byte > serialize(Serializable const &obj)
A method to serialize an object (the object passed as template argument) into a vector of byte.
Definition: Serialization.hpp:91
Enum representing Type of request sent from Network to Client.
Definition: Serialization.hpp:37