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

View file

@ -24,20 +24,20 @@ public:
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
#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
#endif
NetworkPacket(const SharedNodePointer& node, const QByteArray& byteArray);
NetworkPacket(const SharedNodePointer& node, const NLPacket& nlPacket);
const SharedNodePointer& getNode() const { return _node; }
const QByteArray& getByteArray() const { return _byteArray; }
const NLPacket& getPacket() const { return _nlPacket; }
private:
void copyContents(const SharedNodePointer& node, const QByteArray& byteArray);
void copyContents(const SharedNodePointer& node, const NLPacket& nlPacket);
SharedNodePointer _node;
QByteArray _byteArray;
NLPacket _nlPacket;
};
#endif // hifi_NetworkPacket_h