Class PacketUtils

java.lang.Object
net.minestom.server.utils.PacketUtils

public final class PacketUtils extends Object
Utils class for packets. Including writing a ServerPacket into a ByteBuffer for network processing.

Note that all methods are mostly internal and can change at any moment. This is due to their very unsafe nature (use of local buffers as cache) and their potential performance impact. Be sure to check the implementation code.

  • Method Details

    • readPackets

      @Internal @Nullable public static @Nullable BinaryBuffer readPackets(@NotNull @NotNull BinaryBuffer readBuffer, boolean compressed, BiConsumer<Integer,ByteBuffer> payloadConsumer) throws DataFormatException
      Throws:
      DataFormatException
    • writeFramedPacket

      public static void writeFramedPacket(@NotNull @NotNull net.minestom.server.network.ConnectionState state, @NotNull @NotNull ByteBuffer buffer, @NotNull @NotNull ServerPacket packet, boolean compression)
    • writeFramedPacket

      public static void writeFramedPacket(@NotNull @NotNull ByteBuffer buffer, int id, @NotNull NetworkBuffer.Writer writer, int compressionThreshold)
    • createFramedPacket

      @Internal public static ByteBuffer createFramedPacket(@NotNull @NotNull net.minestom.server.network.ConnectionState state, @NotNull @NotNull ByteBuffer buffer, @NotNull @NotNull ServerPacket packet, boolean compression)
    • createFramedPacket

      @Internal public static ByteBuffer createFramedPacket(@NotNull @NotNull net.minestom.server.network.ConnectionState state, @NotNull @NotNull ByteBuffer buffer, @NotNull @NotNull ServerPacket packet)
    • allocateTrimmedPacket

      @Internal public static FramedPacket allocateTrimmedPacket(@NotNull @NotNull net.minestom.server.network.ConnectionState state, @NotNull @NotNull ServerPacket packet)
    • invalidPacketState

      @Internal public static int invalidPacketState(@NotNull @NotNull Class<?> packetClass, @NotNull @NotNull net.minestom.server.network.ConnectionState state, @NotNull @NotNull net.minestom.server.network.ConnectionState... expected)
    • writeVarIntHeader

      public static void writeVarIntHeader(@NotNull @NotNull ByteBuffer buffer, int startIndex, int value)
    • readVarInt

      public static int readVarInt(ByteBuffer buf)