From 46d5f73e4ebdc9715920092eb05e549cc4852f17 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 18 Aug 2015 23:07:08 -0700 Subject: [PATCH] Add support for creating NLPacketList from PacketList --- libraries/networking/src/NLPacketList.cpp | 22 +++++++++++++++++----- libraries/networking/src/NLPacketList.h | 13 +++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libraries/networking/src/NLPacketList.cpp b/libraries/networking/src/NLPacketList.cpp index df36228e7a..6dfd627271 100644 --- a/libraries/networking/src/NLPacketList.cpp +++ b/libraries/networking/src/NLPacketList.cpp @@ -11,15 +11,27 @@ #include "NLPacketList.h" -#include "NLPacket.h" +#include "udt/Packet.h" -NLPacketList::NLPacketList(PacketType packetType, QByteArray extendedHeader) : - PacketList(packetType, extendedHeader) +NLPacketList::NLPacketList(PacketType packetType, QByteArray extendedHeader, bool isReliable, bool isOrdered) : + PacketList(packetType, extendedHeader, isReliable, isOrdered) { +} +NLPacketList::NLPacketList(PacketList&& other) : PacketList(other.getType(), other.getExtendedHeader(), other.isReliable(), other.isOrdered()) { + // Update _packets + for (auto& packet : other._packets) { + auto nlPacket = NLPacket::fromBase(std::move(packet)); + _packets.push_back(std::move(nlPacket)); + } + + if (_packets.size() > 0) { + auto nlPacket = static_cast(_packets.front().get()); + _sourceID = nlPacket->getSourceID(); + _packetType = nlPacket->getType(); + } } std::unique_ptr NLPacketList::createPacket() { - return NLPacket::create(getType()); + return NLPacket::create(getType(), -1, isReliable(), isOrdered()); } - diff --git a/libraries/networking/src/NLPacketList.h b/libraries/networking/src/NLPacketList.h index 512ec23d22..cb48db08f2 100644 --- a/libraries/networking/src/NLPacketList.h +++ b/libraries/networking/src/NLPacketList.h @@ -12,17 +12,26 @@ #ifndef hifi_NLPacketList_h #define hifi_NLPacketList_h +#include + #include "udt/PacketList.h" +#include "NLPacket.h" + class NLPacketList : public udt::PacketList { public: - NLPacketList(PacketType packetType, QByteArray extendedHeader = QByteArray()); + NLPacketList(PacketType packetType, QByteArray extendedHeader = QByteArray(), bool isReliable = false, bool isOrdered = false); + NLPacketList(PacketList&& packetList); + + QUuid getSourceID() const { return _sourceID; } private: NLPacketList(const NLPacketList& other) = delete; NLPacketList& operator=(const NLPacketList& other) = delete; - + virtual std::unique_ptr createPacket(); + + QUuid _sourceID; }; #endif // hifi_PacketList_h