13
0
geforkt von Mirrors/Velocity

Update comments in MinecraftCompressEncoder to be more accurate.

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-08-29 19:11:23 -04:00
Ursprung d28022ab60
Commit fe0d31b0f0

Datei anzeigen

@ -38,9 +38,14 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
@Override
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
throws Exception {
// Follow the advice of https://github.com/ebiggers/libdeflate/blob/master/libdeflate.h#L103
// here for compression. The maximum buffer size if the data compresses well (which is almost
// always the case) is one less the input buffer.
// We allocate bytes to be compressed plus 1 byte. This covers two cases:
//
// - Compression
// According to https://github.com/ebiggers/libdeflate/blob/master/libdeflate.h#L103,
// if the data compresses well (and we do not have some pathological case) then the maximum
// size the compressed size will ever be is the input size minus one.
// - Uncompressed
// This is fairly obvious - we will then have one more than the uncompressed size.
int initialBufferSize = msg.readableBytes() + 1;
return MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, initialBufferSize);
}