56 lines
1.5 KiB
Java
56 lines
1.5 KiB
Java
![]() |
package game.network;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
import game.net.buffer.ByteBuf;
|
||
|
import game.net.buffer.Unpooled;
|
||
|
import game.net.channel.ChannelHandlerContext;
|
||
|
import game.net.handler.codec.ByteToMessageDecoder;
|
||
|
import game.net.handler.codec.CorruptedFrameException;
|
||
|
|
||
|
public class PacketSplitter extends ByteToMessageDecoder
|
||
|
{
|
||
|
protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List<Object> p_decode_3_) throws Exception
|
||
|
{
|
||
|
p_decode_2_.markReaderIndex();
|
||
|
byte[] abyte = new byte[3];
|
||
|
|
||
|
for (int i = 0; i < abyte.length; ++i)
|
||
|
{
|
||
|
if (!p_decode_2_.isReadable())
|
||
|
{
|
||
|
p_decode_2_.resetReaderIndex();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
abyte[i] = p_decode_2_.readByte();
|
||
|
|
||
|
if (abyte[i] >= 0)
|
||
|
{
|
||
|
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(abyte));
|
||
|
|
||
|
try
|
||
|
{
|
||
|
int j = packetbuffer.readVarIntFromBuffer();
|
||
|
|
||
|
if (p_decode_2_.readableBytes() >= j)
|
||
|
{
|
||
|
p_decode_3_.add(p_decode_2_.readBytes(j));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
p_decode_2_.resetReaderIndex();
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
packetbuffer.release();
|
||
|
}
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
throw new CorruptedFrameException("length wider than 21-bit");
|
||
|
}
|
||
|
}
|