Don't use a bytebuf for packet decoding

This commit is contained in:
creeper123123321 2019-01-17 03:26:52 +00:00 committed by Shane Freeder
parent 2af9e83888
commit 7f6187dfe1
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C

View File

@ -0,0 +1,71 @@
From 55dc9beefb1976dba1595821e640072020f1b701 Mon Sep 17 00:00:00 2001
From: creeper123123321 <creeper123123321@gmail.com>
Date: Thu, 17 Jan 2019 03:25:59 +0000
Subject: [PATCH] Don't use a bytebuf for packet decoding
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index 880a3dc7..8680e4f4 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -25,8 +25,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
in.markReaderIndex();
- final byte[] buf = new byte[ 3 ];
- for ( int i = 0; i < buf.length; i++ )
+ for ( int i = 0; i < 3; i++ ) // Waterfall
{
if ( !in.isReadable() )
{
@@ -34,10 +33,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
return;
}
- buf[i] = in.readByte();
- if ( buf[i] >= 0 )
+ // Waterfall start
+ byte read = in.readByte();
+ if ( read >= 0 )
{
- int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
+ in.resetReaderIndex();
+ int length = DefinedPacket.readVarInt( in );
+ // Waterfall end
if ( length == 0 && !allowEmptyPackets) // Waterfall
{
throw new CorruptedFrameException( "Empty Packet!" );
@@ -47,26 +49,10 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
in.resetReaderIndex();
return;
- } else
- {
- if ( in.hasMemoryAddress() )
- {
- out.add( in.slice( in.readerIndex(), length ).retain() );
- in.skipBytes( length );
- } else
- {
- if ( !DIRECT_WARNING )
- {
- DIRECT_WARNING = true;
- System.out.println( "Netty is not using direct IO buffers." );
- }
-
- // See https://github.com/SpigotMC/BungeeCord/issues/1717
- ByteBuf dst = ctx.alloc().directBuffer( length );
- in.readBytes( dst );
- out.add( dst );
- }
- return;
+ // Waterfall start
+ } else {
+ out.add(in.readRetainedSlice(length));
+ // Waterfall end
}
}
}
--
2.20.1