compress refactor

This commit is contained in:
2025-02-27 21:45:09 +01:00
parent 6a52b7fe2a
commit f6620dc522
4 changed files with 48 additions and 17 deletions

View File

@@ -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