mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Better name for the local deflater, add link to the packet format
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
16dba78afe
commit
21bac6fba4
@ -38,7 +38,7 @@ import java.util.zip.Deflater;
|
|||||||
*/
|
*/
|
||||||
public final class PacketUtils {
|
public final class PacketUtils {
|
||||||
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
|
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
|
||||||
private static final ThreadLocal<Deflater> COMPRESSOR = ThreadLocal.withInitial(Deflater::new);
|
private static final ThreadLocal<Deflater> LOCAL_DEFLATER = ThreadLocal.withInitial(Deflater::new);
|
||||||
private static final LocalCache PACKET_BUFFER = LocalCache.get("packet-buffer", Server.MAX_PACKET_SIZE);
|
private static final LocalCache PACKET_BUFFER = LocalCache.get("packet-buffer", Server.MAX_PACKET_SIZE);
|
||||||
private static final LocalCache COMPRESSION_CACHE = LocalCache.get("compression-buffer", Server.MAX_PACKET_SIZE);
|
private static final LocalCache COMPRESSION_CACHE = LocalCache.get("compression-buffer", Server.MAX_PACKET_SIZE);
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ public final class PacketUtils {
|
|||||||
@NotNull ServerPacket packet,
|
@NotNull ServerPacket packet,
|
||||||
boolean compression) {
|
boolean compression) {
|
||||||
if (!compression) {
|
if (!compression) {
|
||||||
// Length + payload
|
// Uncompressed format https://wiki.vg/Protocol#Without_compression
|
||||||
final int lengthIndex = Utils.writeEmptyVarIntHeader(buffer);
|
final int lengthIndex = Utils.writeEmptyVarIntHeader(buffer);
|
||||||
Utils.writeVarInt(buffer, packet.getId());
|
Utils.writeVarInt(buffer, packet.getId());
|
||||||
packet.write(new BinaryWriter(buffer));
|
packet.write(new BinaryWriter(buffer));
|
||||||
@ -187,7 +187,7 @@ public final class PacketUtils {
|
|||||||
Utils.writeVarIntHeader(buffer, lengthIndex, finalSize);
|
Utils.writeVarIntHeader(buffer, lengthIndex, finalSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Compressed format
|
// Compressed format https://wiki.vg/Protocol#With_compression
|
||||||
final int compressedIndex = Utils.writeEmptyVarIntHeader(buffer);
|
final int compressedIndex = Utils.writeEmptyVarIntHeader(buffer);
|
||||||
final int uncompressedIndex = Utils.writeEmptyVarIntHeader(buffer);
|
final int uncompressedIndex = Utils.writeEmptyVarIntHeader(buffer);
|
||||||
final int contentStart = buffer.position();
|
final int contentStart = buffer.position();
|
||||||
@ -201,7 +201,7 @@ public final class PacketUtils {
|
|||||||
final ByteBuffer uncompressedContent = buffer.slice().limit(packetSize);
|
final ByteBuffer uncompressedContent = buffer.slice().limit(packetSize);
|
||||||
final ByteBuffer uncompressedCopy = localBuffer().put(uncompressedContent).flip();
|
final ByteBuffer uncompressedCopy = localBuffer().put(uncompressedContent).flip();
|
||||||
|
|
||||||
Deflater deflater = COMPRESSOR.get();
|
Deflater deflater = LOCAL_DEFLATER.get();
|
||||||
deflater.setInput(uncompressedCopy);
|
deflater.setInput(uncompressedCopy);
|
||||||
deflater.finish();
|
deflater.finish();
|
||||||
deflater.deflate(buffer);
|
deflater.deflate(buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user