13
0
geforkt von Mirrors/Velocity

Avoid ByteBuf#slice(). We can simply reset the reader index.

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-01-12 00:25:11 -05:00
Ursprung 1a2b162353
Commit 564b87de1d

Datei anzeigen

@ -17,7 +17,7 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
return; return;
} }
ByteBuf lenBuf = ctx.alloc().buffer(3); ByteBuf lenBuf = ctx.alloc().buffer(3).writeZero(3);
int origReaderIndex = in.readerIndex(); int origReaderIndex = in.readerIndex();
try { try {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -27,9 +27,11 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
} }
byte read = in.readByte(); byte read = in.readByte();
lenBuf.writeByte(read); lenBuf.setByte(i, read);
if (read > 0) { if (read > 0) {
int packetLength = ProtocolUtils.readVarInt(lenBuf.slice()); // Make sure reader index of length buffer is returned to the beginning
lenBuf.readerIndex(0);
int packetLength = ProtocolUtils.readVarInt(lenBuf);
if (packetLength == 0) { if (packetLength == 0) {
return; return;
} }