Update NetworkPacket to use NLPacket

This commit is contained in:
Ryan Huffman 2015-07-07 12:15:44 -07:00
parent 18dd61ec7e
commit ebd223ecba
2 changed files with 14 additions and 14 deletions

View file

@ -18,38 +18,38 @@
#include "NetworkPacket.h" #include "NetworkPacket.h"
void NetworkPacket::copyContents(const SharedNodePointer& node, const QByteArray& packet) { void NetworkPacket::copyContents(const SharedNodePointer& node, const NLPacket& packet) {
if (packet.size() && packet.size() <= MAX_PACKET_SIZE) { if (packet.size() && packet.size() <= MAX_PACKET_SIZE) {
_node = node; _node = node;
_byteArray = packet; _nlPacket = packet;
} else { } else {
qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size()); qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
} }
} }
NetworkPacket::NetworkPacket(const NetworkPacket& packet) { NetworkPacket::NetworkPacket(const NetworkPacket& other) {
copyContents(packet.getNode(), packet.getByteArray()); copyContents(other._node, other._packet);
} }
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const QByteArray& packet) { NetworkPacket::NetworkPacket(const SharedNodePointer& node, const NLPacket& packet) {
copyContents(node, packet); copyContents(node, packet);
}; };
// copy assignment // copy assignment
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) { NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
copyContents(other.getNode(), other.getByteArray()); copyContents(other._node, other._packet);
return *this; return *this;
} }
#ifdef HAS_MOVE_SEMANTICS #ifdef HAS_MOVE_SEMANTICS
// move, same as copy, but other packet won't be used further // move, same as copy, but other packet won't be used further
NetworkPacket::NetworkPacket(NetworkPacket && packet) { NetworkPacket::NetworkPacket(NetworkPacket&& other) {
copyContents(packet.getNode(), packet.getByteArray()); copyContents(other._node, other._packet);
} }
// move assignment // move assignment
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) { NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
copyContents(other.getNode(), other.getByteArray()); copyContents(other._node, other._packet);
return *this; return *this;
} }
#endif #endif

View file

@ -24,20 +24,20 @@ public:
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
#ifdef HAS_MOVE_SEMANTICS #ifdef HAS_MOVE_SEMANTICS
NetworkPacket(NetworkPacket&& packet); // move?? // same as copy, but other packet won't be used further NetworkPacket(NetworkPacket&& other); // move?? // same as copy, but other packet won't be used further
NetworkPacket& operator= (NetworkPacket&& other); // move assignment NetworkPacket& operator= (NetworkPacket&& other); // move assignment
#endif #endif
NetworkPacket(const SharedNodePointer& node, const QByteArray& byteArray); NetworkPacket(const SharedNodePointer& node, const NLPacket& nlPacket);
const SharedNodePointer& getNode() const { return _node; } const SharedNodePointer& getNode() const { return _node; }
const QByteArray& getByteArray() const { return _byteArray; } const NLPacket& getPacket() const { return _nlPacket; }
private: private:
void copyContents(const SharedNodePointer& node, const QByteArray& byteArray); void copyContents(const SharedNodePointer& node, const NLPacket& nlPacket);
SharedNodePointer _node; SharedNodePointer _node;
QByteArray _byteArray; NLPacket _nlPacket;
}; };
#endif // hifi_NetworkPacket_h #endif // hifi_NetworkPacket_h