Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Decode multiple VarInt-prefixed packets
If the remote server does flush consolidation, Velocity will be able to frame the packets all at once instead of having to constantly decode packets. This should provide a modest performance boost for them whilst not impacting un-optimized servers.
Dieser Commit ist enthalten in:
Ursprung
138a887d73
Commit
009c9afe09
@ -11,36 +11,35 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||||
if (!in.isReadable()) {
|
int lastReaderIndex = in.readerIndex();
|
||||||
return;
|
find_packets: while (in.isReadable()) {
|
||||||
}
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (!in.isReadable()) {
|
||||||
int origReaderIndex = in.readerIndex();
|
break;
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if (!in.isReadable()) {
|
|
||||||
in.readerIndex(origReaderIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte read = in.readByte();
|
|
||||||
if (read >= 0) {
|
|
||||||
// Make sure reader index of length buffer is returned to the beginning
|
|
||||||
in.readerIndex(origReaderIndex);
|
|
||||||
int packetLength = ProtocolUtils.readVarInt(in);
|
|
||||||
if (packetLength == 0) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in.readableBytes() < packetLength) {
|
byte read = in.readByte();
|
||||||
in.readerIndex(origReaderIndex);
|
if (read >= 0) {
|
||||||
return;
|
// Make sure reader index of length buffer is returned to the beginning
|
||||||
}
|
in.readerIndex(lastReaderIndex);
|
||||||
|
int packetLength = ProtocolUtils.readVarInt(in);
|
||||||
|
if (packetLength == 0) {
|
||||||
|
break find_packets;
|
||||||
|
}
|
||||||
|
|
||||||
out.add(in.readRetainedSlice(packetLength));
|
if (in.readableBytes() < packetLength) {
|
||||||
return;
|
break find_packets;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.add(in.readRetainedSlice(packetLength));
|
||||||
|
lastReaderIndex = in.readerIndex();
|
||||||
|
continue find_packets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new CorruptedFrameException("VarInt too big");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CorruptedFrameException("VarInt too big");
|
in.readerIndex(lastReaderIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren