compress refactor
This commit is contained in:
@@ -34,21 +34,13 @@ DataBuffer Compress(const DataBuffer& buffer, std::size_t a_CompressionThreshold
|
||||
|
||||
if (buffer.GetSize() < a_CompressionThreshold) {
|
||||
// Don't compress since it's a small packet
|
||||
VarInt compressedDataLength = 0;
|
||||
VarInt packetLength = compressedDataLength.GetSerializedLength() + buffer.GetSize();
|
||||
|
||||
packet << packetLength;
|
||||
packet << compressedDataLength;
|
||||
packet << VarInt{0};
|
||||
packet << buffer;
|
||||
return packet;
|
||||
}
|
||||
|
||||
DataBuffer compressedData = Deflate(buffer.data(), buffer.GetSize());
|
||||
|
||||
VarInt uncompressedDataLength = buffer.GetSize();
|
||||
VarInt packetLength = uncompressedDataLength.GetSerializedLength() + compressedData.GetSize();
|
||||
|
||||
packet << packetLength;
|
||||
|
||||
if (compressedData.GetSize() >= buffer.GetSize()) {
|
||||
// the compression is overkill so we don't send the compressed buffer
|
||||
|
||||
Reference in New Issue
Block a user