diff --git a/include/E/Networking/E_Packet.hpp b/include/E/Networking/E_Packet.hpp index 3e6af57b5..955250e0f 100644 --- a/include/E/Networking/E_Packet.hpp +++ b/include/E/Networking/E_Packet.hpp @@ -25,10 +25,10 @@ class Packet : public Module::MessageBase { private: Packet(UUID uuid, size_t maxSize); std::vector buffer; - const size_t bufferSize; + size_t bufferSize; size_t dataSize; - const UUID packetID; + UUID packetID; static std::unordered_set packetUUIDSet; static UUID packetUUIDStart; @@ -48,6 +48,18 @@ class Packet : public Module::MessageBase { */ Packet(Packet &&other) noexcept; + /** + * Copy assignment operator. (Copied packet has same UUID) + * @param other Packet to copy. + */ + Packet &operator=(const Packet &other); + + /** + * Move assignment operator. (Moved packet become emtpy) + * @param other Packet to move. + */ + Packet &operator=(Packet &&other) noexcept; + /** * @param maxSize Maximum packet size. */ diff --git a/src/Networking/E_Packet.cpp b/src/Networking/E_Packet.cpp index 926381944..169ecf86b 100644 --- a/src/Networking/E_Packet.cpp +++ b/src/Networking/E_Packet.cpp @@ -43,6 +43,22 @@ Packet::Packet(Packet &&other) noexcept other.dataSize = 0; } +Packet &Packet::operator=(const Packet &other) { + buffer = other.buffer; + bufferSize = other.bufferSize; + dataSize = other.dataSize; + packetID = other.packetID; + return *this; +} + +Packet &Packet::operator=(Packet &&other) noexcept { + buffer = std::move(other.buffer); + bufferSize = std::move(other.bufferSize); + dataSize = std::move(other.dataSize); + packetID = std::move(other.packetID); + return *this; +} + Packet::Packet(size_t maxSize) : Packet(allocatePacketUUID(), maxSize) {} Packet::~Packet() { freePacketUUID(this->packetID); }