Package net.minestom.server.utils
Class PacketUtils
java.lang.Object
net.minestom.server.utils.PacketUtils
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 Summary
Modifier and TypeMethodDescriptionstatic FramedPacketallocateTrimmedPacket(@NotNull net.minestom.server.network.ConnectionState state, @NotNull ServerPacket packet) static ByteBuffercreateFramedPacket(@NotNull net.minestom.server.network.ConnectionState state, @NotNull ByteBuffer buffer, @NotNull ServerPacket packet) static ByteBuffercreateFramedPacket(@NotNull net.minestom.server.network.ConnectionState state, @NotNull ByteBuffer buffer, @NotNull ServerPacket packet, boolean compression) static intinvalidPacketState(@NotNull Class<?> packetClass, @NotNull net.minestom.server.network.ConnectionState state, @NotNull net.minestom.server.network.ConnectionState... expected) static @Nullable BinaryBufferreadPackets(@NotNull BinaryBuffer readBuffer, boolean compressed, BiConsumer<Integer, ByteBuffer> payloadConsumer) static intreadVarInt(ByteBuffer buf) static voidwriteFramedPacket(@NotNull ByteBuffer buffer, int id, NetworkBuffer.Writer writer, int compressionThreshold) static voidwriteFramedPacket(@NotNull net.minestom.server.network.ConnectionState state, @NotNull ByteBuffer buffer, @NotNull ServerPacket packet, boolean compression) static voidwriteVarIntHeader(@NotNull ByteBuffer buffer, int startIndex, int value)
-
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
-