mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:24:00 +02:00
Fail with packet size in constructor
This commit is contained in:
parent
c77310019d
commit
a2a60f253c
2 changed files with 7 additions and 21 deletions
|
@ -30,16 +30,6 @@ qint64 NLPacket::localHeaderSize() const {
|
|||
}
|
||||
|
||||
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, qint64 size) {
|
||||
auto maxPayload = maxPayloadSize(type);
|
||||
if (size == -1) {
|
||||
// default size of -1, means biggest packet possible
|
||||
size = maxPayload;
|
||||
}
|
||||
|
||||
// Fail with invalid size
|
||||
Q_ASSERT(size >= 0 || size < maxPayload);
|
||||
|
||||
// allocate memory
|
||||
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,16 +24,6 @@ qint64 Packet::maxPayloadSize(PacketType::Value type) {
|
|||
}
|
||||
|
||||
std::unique_ptr<Packet> Packet::create(PacketType::Value type, qint64 size) {
|
||||
auto maxPayload = maxPayloadSize(type);
|
||||
if (size == -1) {
|
||||
// default size of -1, means biggest packet possible
|
||||
size = maxPayload;
|
||||
}
|
||||
|
||||
// Fail with invalid size
|
||||
Q_ASSERT(size >= 0 || size < maxPayload);
|
||||
|
||||
// allocate memory
|
||||
return std::unique_ptr<Packet>(new Packet(type, size));
|
||||
}
|
||||
|
||||
|
@ -55,8 +45,14 @@ Packet::Packet(PacketType::Value type, qint64 size) :
|
|||
_packet(new char(_packetSize)),
|
||||
_payloadStart(_packet.get() + localHeaderSize(_type)),
|
||||
_capacity(size) {
|
||||
auto maxPayload = maxPayloadSize(type);
|
||||
if (size == -1) {
|
||||
// default size of -1, means biggest packet possible
|
||||
size = maxPayload;
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
Q_ASSERT(size <= maxPayloadSize(type));
|
||||
Q_ASSERT(size >= 0 || size < maxPayload);
|
||||
|
||||
// copy packet type and version in header
|
||||
writePacketTypeAndVersion(type);
|
||||
|
|
Loading…
Reference in a new issue