From 1e041963f0f20d89f176608c9887c0ed54065a62 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 11 Jan 2019 18:04:51 -0500 Subject: [PATCH] Use just one byte array in the varint frame decoder. --- .../proxy/protocol/netty/MinecraftVarintFrameDecoder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index 9d42edfd1..dfe0e25b4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -6,19 +6,22 @@ import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.CorruptedFrameException; +import java.util.Arrays; import java.util.List; public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { + private final byte[] lenBuf = new byte[3]; + @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { if (!in.isReadable()) { return; } + Arrays.fill(lenBuf, (byte) 0); int origReaderIndex = in.readerIndex(); - byte[] lenBuf = new byte[3]; ByteBuf wrappedBuf = Unpooled.wrappedBuffer(lenBuf); for (int i = 0; i < lenBuf.length; i++) { if (!in.isReadable()) {