mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-05 19:47:00 -04:00
Add packet size log prints
This commit is contained in:
parent
9b856c0b58
commit
fcb8b71e36
1 changed files with 34 additions and 0 deletions
|
@ -25,9 +25,11 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
|
@ -90,6 +92,38 @@ public final class RegistrySyncManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void receivePacket(ThreadExecutor<?> executor, RegistrySyncPacket packet, PacketByteBuf buf, boolean accept, Consumer<Exception> errorHandler) {
|
public static void receivePacket(ThreadExecutor<?> executor, RegistrySyncPacket packet, PacketByteBuf buf, boolean accept, Consumer<Exception> errorHandler) {
|
||||||
|
if (DEBUG) {
|
||||||
|
LOGGER.info("{} raw size: {}", packet.getClass().getSimpleName(), buf.readableBytes());
|
||||||
|
|
||||||
|
// see PacketDeflater
|
||||||
|
final byte[] deflateBuffer = new byte[8192];
|
||||||
|
ByteBuf byteBuf = buf.copy();
|
||||||
|
Deflater deflater = new Deflater();
|
||||||
|
|
||||||
|
int i = byteBuf.readableBytes();
|
||||||
|
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
|
||||||
|
|
||||||
|
if (i < 256) {
|
||||||
|
packetByteBuf.writeVarInt(0);
|
||||||
|
packetByteBuf.writeBytes(byteBuf);
|
||||||
|
} else {
|
||||||
|
byte[] bs = new byte[i];
|
||||||
|
byteBuf.readBytes(bs);
|
||||||
|
packetByteBuf.writeVarInt(bs.length);
|
||||||
|
deflater.setInput(bs, 0, i);
|
||||||
|
deflater.finish();
|
||||||
|
|
||||||
|
while (!deflater.finished()) {
|
||||||
|
int j = deflater.deflate(deflateBuffer);
|
||||||
|
packetByteBuf.writeBytes(deflateBuffer, 0, j);
|
||||||
|
}
|
||||||
|
|
||||||
|
deflater.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info("{} deflated size: {}", packet.getClass().getSimpleName(), packetByteBuf.readableBytes());
|
||||||
|
}
|
||||||
|
|
||||||
RegistryMap map = packet.readBuffer(buf);
|
RegistryMap map = packet.readBuffer(buf);
|
||||||
|
|
||||||
if (accept) {
|
if (accept) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue