Added NLPacket::createCopy

This commit is contained in:
Atlante45 2015-07-07 16:27:48 -07:00
parent e0119e8767
commit fcd11461c2
4 changed files with 15 additions and 7 deletions

View file

@ -37,9 +37,17 @@ std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, int64_t size)
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
}
std::unique_ptr<NLPacket> NLPacket::createCopy(const std::unique_ptr<NLPacket>& other) {
Q_ASSERT(other);
return std::unique_ptr<NLPacket>(new NLPacket(*other));
}
NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, localHeaderSize(type) + size) {
}
NLPacket::NLPacket(NLPacket& other) : Packet(other) {
}
void NLPacket::setSourceUuid(QUuid sourceUuid) {
Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type));
auto offset = Packet::totalHeadersSize();

View file

@ -17,6 +17,8 @@
class NLPacket : public Packet {
public:
static std::unique_ptr<NLPacket> create(PacketType::Value type, int64_t size = -1);
// Provided for convenience, try to limit use
static std::unique_ptr<NLPacket> createCopy(const std::unique_ptr<NLPacket>& other);
static int64_t localHeaderSize(PacketType::Value type);
static int64_t maxPayloadSize(PacketType::Value type);
@ -26,6 +28,7 @@ public:
protected:
NLPacket(PacketType::Value type, int64_t size);
NLPacket(NLPacket& other);
void setSourceUuid(QUuid sourceUuid);
void setConnectionUuid(QUuid connectionUuid);

View file

@ -38,7 +38,6 @@ std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
return std::unique_ptr<Packet>(new Packet(type, size));
}
std::unique_ptr<Packet> Packet::createCopy(const std::unique_ptr<Packet>& other) {
Q_ASSERT(other);
return std::unique_ptr<Packet>(new Packet(*other));

View file

@ -61,6 +61,10 @@ public:
protected:
Packet(PacketType::Value type, int64_t size);
Packet(const Packet& other);
Packet& operator=(const Packet& other);
Packet(Packet&& other);
Packet& operator=(Packet&& other);
// QIODevice virtual functions
virtual qint64 writeData(const char* data, qint64 maxSize);
@ -79,12 +83,6 @@ protected:
qint64 _capacity = 0; // Total capacity of the payload
qint64 _sizeUsed = 0; // How much of the payload is actually used
private:
Packet(const Packet& other);
Packet& operator=(const Packet& other);
Packet(Packet&& other);
Packet& operator=(Packet&& other);
};
#endif // hifi_Packet_h