change createCopy in packet to take const &

This commit is contained in:
Stephen Birarda 2015-07-09 11:23:44 -07:00
parent 659f6742c6
commit bd9b42bd4c
4 changed files with 8 additions and 10 deletions

View file

@ -33,13 +33,12 @@ std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, int64_t size)
if (size > maxPayloadSize(type)) {
return std::unique_ptr<NLPacket>();
}
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));
std::unique_ptr<NLPacket> NLPacket::createCopy(const NLPacket& other) {
return std::unique_ptr<NLPacket>(new NLPacket(other));
}
NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, localHeaderSize(type) + size) {
@ -59,4 +58,4 @@ void NLPacket::setConnectionUuid(QUuid connectionUuid) {
auto offset = Packet::totalHeadersSize() +
((NON_SOURCED_PACKETS.contains(_type)) ? 0 : NUM_BYTES_RFC4122_UUID);
memcpy(_packet.get() + offset, connectionUuid.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
}
}

View file

@ -19,7 +19,7 @@ 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 std::unique_ptr<NLPacket> createCopy(const NLPacket& other);
static int64_t localHeaderSize(PacketType::Value type);
static int64_t maxPayloadSize(PacketType::Value type);

View file

@ -38,9 +38,8 @@ 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));
std::unique_ptr<Packet> Packet::createCopy(const Packet& other) {
return std::unique_ptr<Packet>(new Packet(other));
}
qint64 Packet::totalHeadersSize() const {

View file

@ -25,7 +25,7 @@ public:
static std::unique_ptr<Packet> create(PacketType::Value type, int64_t size = -1);
// Provided for convenience, try to limit use
static std::unique_ptr<Packet> createCopy(const std::unique_ptr<Packet>& other);
static std::unique_ptr<Packet> createCopy(const Packet& other);
static qint64 localHeaderSize(PacketType::Value type);
static qint64 maxPayloadSize(PacketType::Value type);