Contents
- Description
- Field Summary
- Method Summary
- Field Details
- Method Details
- readBytes(ByteBuf, int, int)
- readFixedAsciiString(ByteBuf, int, int)
- readFixedString(ByteBuf, int, int)
- readFixedAsciiString(MemorySegment, int, int)
- readFixedString(MemorySegment, int, int)
- readVarString(ByteBuf, int)
- readVarString(ByteBuf, int, Charset)
- readValidatedAsciiString(ByteBuf, int, int, String)
- readVarString(String, MemorySegment, int, int, int)
- readVarString(String, MemorySegment, int, int, int, long)
- isWellFormedUtf8(byte[])
- readVarString(String, MemorySegment, int, int)
- readValidatedAsciiString(String, MemorySegment, int, int, int)
- readValidatedAsciiString(String, MemorySegment, int, int, int, long)
- readValidatedAsciiString(String, MemorySegment, int, int)
- requireFinite(float, String)
- requireFinite(double, String)
- isFinite(float)
- isFinite(double)
- isFinite(Vector2fc)
- isFinite(Vector3fc)
- isFinite(Vector4fc)
- isFinite(Quaternionfc)
- isFinite(Matrix4fc)
- requireFinite(Vector2fc, String)
- requireFinite(Vector3fc, String)
- requireFinite(Vector4fc, String)
- requireFinite(Quaternionfc, String)
- requireFinite(Matrix4fc, String)
- utf8ByteLength(String)
- stringSize(String)
- writeFixedAsciiString(ByteBuf, String, int)
- writeFixedString(ByteBuf, String, int)
- writeVarString(ByteBuf, String, int)
- writeVarAsciiString(ByteBuf, String, int)
- writeVarString(MemorySegment, int, String, int)
- writeVarAsciiString(MemorySegment, int, String, int)
- readVector2f(MemorySegment, int)
- readVector3f(MemorySegment, int)
- readVector4f(MemorySegment, int)
- readQuaternionf(MemorySegment, int)
- writeVector2f(MemorySegment, int, Vector2fc)
- writeVector3f(MemorySegment, int, Vector3fc)
- writeVector4f(MemorySegment, int, Vector4fc)
- writeQuaternionf(MemorySegment, int, Quaternionfc)
- writeFixedAsciiString(MemorySegment, int, String, int)
- writeFixedString(MemorySegment, int, String, int)
- readUUID(ByteBuf, int)
- writeUUID(ByteBuf, UUID)
- readUUID(MemorySegment, int)
- writeUUID(MemorySegment, int, UUID)
- halfToFloat(short)
- floatToHalf(float)
- writeFramedPacket(Packet, Class, ByteBuf, ByteBufAllocator, PacketStatsRecorder)
- writeFramedPacketWithInfo(Packet, PacketRegistry.PacketInfo, ByteBuf, ByteBufAllocator, PacketStatsRecorder)
- readFramedPacket(ByteBuf, int, ByteBufAllocator, PacketStatsRecorder)
- readFramedPacketWithInfo(ByteBuf, int, ByteBufAllocator, PacketRegistry.PacketInfo, PacketStatsRecorder)
- writeFramedPacket(MemorySegment, Packet, PacketRegistry.PacketInfo, MemorySegment, int, int, PacketStatsRecorder)
- readFramedPacket(MemorySegment, MemorySegment, int, PacketStatsRecorder)
- readFramedPacketWithInfo(MemorySegment, MemorySegment, int, int, PacketRegistry.PacketInfo, PacketStatsRecorder)
Class PacketIO
java.lang.Object
com.hypixel.hytale.protocol.io.PacketIO
Utility class for reading and writing protocol data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Charsetstatic final intHeader size for framed packets (4 bytes for packet ID).static final intPacket header size, 4 bytes for id, 4 bytes for lengthstatic final ValueLayout.OfBooleanstatic final ValueLayout.OfBytestatic final ValueLayout.OfDoublestatic final ValueLayout.OfFloatstatic final ValueLayout.OfIntstatic final ValueLayout.OfLongstatic final ValueLayout.OfShortstatic final Charsetstatic final ValueLayout.OfLongstatic final org.joml.Matrix4fcstatic final org.joml.Quaternionfcstatic final org.joml.Vector2fcstatic final org.joml.Vector3fcstatic final org.joml.Vector4fc -
Method Summary
Modifier and TypeMethodDescriptionstatic shortfloatToHalf(float f) static floathalfToFloat(short half) static booleanisFinite(double value) True ifvalueis finite.static booleanisFinite(float value) True ifvalueis finite.static booleanisFinite(org.joml.Matrix4fc m) True if every one of the 16 components ofmis finite.static booleanisFinite(org.joml.Quaternionfc q) True if every component ofqis finite.static booleanisFinite(org.joml.Vector2fc v) True if every component ofvis finite.static booleanisFinite(org.joml.Vector3fc v) True if every component ofvis finite.static booleanisFinite(org.joml.Vector4fc v) True if every component ofvis finite.static booleanisWellFormedUtf8(byte[] bytes) Table 3-7 of the Unicode standard.static byte[]readBytes(io.netty.buffer.ByteBuf buf, int offset, int length) static StringreadFixedAsciiString(io.netty.buffer.ByteBuf buf, int offset, int length) static StringreadFixedAsciiString(MemorySegment mem, int offset, int length) static StringreadFixedString(io.netty.buffer.ByteBuf buf, int offset, int length) static StringreadFixedString(MemorySegment mem, int offset, int length) static PacketreadFramedPacket(io.netty.buffer.ByteBuf in, int payloadLength, io.netty.buffer.ByteBufAllocator allocator, PacketStatsRecorder statsRecorder) Read a framed packet from a ByteBuf.static PacketreadFramedPacket(MemorySegment decompressionContext, MemorySegment in, int payloadLength, PacketStatsRecorder statsRecorder) static PacketreadFramedPacketWithInfo(io.netty.buffer.ByteBuf in, int payloadLength, io.netty.buffer.ByteBufAllocator allocator, PacketRegistry.PacketInfo info, PacketStatsRecorder statsRecorder) Read a framed packet with pre-validated PacketInfo (packet ID and size already validated).static PacketreadFramedPacketWithInfo(MemorySegment decompressionContext, MemorySegment in, int offset, int payloadLength, PacketRegistry.PacketInfo info, PacketStatsRecorder statsRecorder) static org.joml.QuaternionfreadQuaternionf(MemorySegment mem, int offset) static UUIDreadUUID(io.netty.buffer.ByteBuf buf, int offset) static UUIDreadUUID(MemorySegment mem, int offset) static StringreadValidatedAsciiString(io.netty.buffer.ByteBuf buf, int offset, int length, String fieldName) Reads bytes from the buffer, validates they are ASCII (0-127), and returns the decoded string.static StringreadValidatedAsciiString(String fieldName, MemorySegment mem, int offset, int maxLength) static StringreadValidatedAsciiString(String fieldName, MemorySegment mem, int offset, int minLength, int maxLength) Reads a length-prefixed ASCII string from a MemorySegment, validating every byte is in the ASCII range (0-127).static StringreadValidatedAsciiString(String fieldName, MemorySegment mem, int offset, int minLength, int maxLength, long packed) The packed parameter is the VarInt.getWithLength result for offset, so a caller that already decoded the prefix does not decode it twice.static StringreadVarString(io.netty.buffer.ByteBuf buf, int offset) static StringreadVarString(io.netty.buffer.ByteBuf buf, int offset, Charset charset) static StringreadVarString(String fieldName, MemorySegment mem, int offset, int maxLength) static StringreadVarString(String fieldName, MemorySegment mem, int offset, int minLength, int maxLength) static StringreadVarString(String fieldName, MemorySegment mem, int offset, int minLength, int maxLength, long packed) The packed parameter is the VarInt.getWithLength result for offset, so a caller that already decoded the prefix does not decode it twice.static org.joml.Vector2freadVector2f(MemorySegment mem, int offset) static org.joml.Vector3freadVector3f(MemorySegment mem, int offset) static org.joml.Vector4freadVector4f(MemorySegment mem, int offset) static doublerequireFinite(double value, String fieldName) Returnsvalueif it is finite, otherwise throws.static floatrequireFinite(float value, String fieldName) Returnsvalueif it is finite (not NaN and not infinite), otherwise throws aProtocolException.static org.joml.Matrix4fcrequireFinite(org.joml.Matrix4fc m, String fieldName) Returnsmif every component is finite, otherwise throws.static org.joml.QuaternionfcrequireFinite(org.joml.Quaternionfc q, String fieldName) Returnsqif every component is finite, otherwise throws.static org.joml.Vector2fcrequireFinite(org.joml.Vector2fc v, String fieldName) Returnsvif every component is finite, otherwise throws.static org.joml.Vector3fcrequireFinite(org.joml.Vector3fc v, String fieldName) Returnsvif every component is finite, otherwise throws.static org.joml.Vector4fcrequireFinite(org.joml.Vector4fc v, String fieldName) Returnsvif every component is finite, otherwise throws.static intstringSize(String s) Compute the total wire size of a VarInt-prefixed UTF-8 string.static intCompute the number of UTF-8 bytes needed to encode a string.static voidwriteFixedAsciiString(io.netty.buffer.ByteBuf buf, String value, int length) static voidwriteFixedAsciiString(MemorySegment mem, int offset, String value, int length) static voidwriteFixedString(io.netty.buffer.ByteBuf buf, String value, int length) static voidwriteFixedString(MemorySegment mem, int offset, String value, int length) static voidwriteFramedPacket(Packet packet, Class<? extends Packet> packetClass, io.netty.buffer.ByteBuf out, io.netty.buffer.ByteBufAllocator allocator, PacketStatsRecorder statsRecorder) Write a packet with framing, using an explicit packet class for registry lookup.static intwriteFramedPacket(MemorySegment compressionContext, Packet packet, PacketRegistry.PacketInfo packetInfo, MemorySegment out, int offset, int packetSize, PacketStatsRecorder statsRecorder) static voidwriteFramedPacketWithInfo(Packet packet, PacketRegistry.PacketInfo info, io.netty.buffer.ByteBuf out, io.netty.buffer.ByteBufAllocator allocator, PacketStatsRecorder statsRecorder) static voidwriteQuaternionf(MemorySegment mem, int offset, org.joml.Quaternionfc q) static voidstatic voidwriteUUID(MemorySegment mem, int offset, UUID value) static voidwriteVarAsciiString(io.netty.buffer.ByteBuf buf, String value, int maxLength) static intwriteVarAsciiString(MemorySegment mem, int offset, String value, int maxLength) static voidwriteVarString(io.netty.buffer.ByteBuf buf, String value, int maxLength) static intwriteVarString(MemorySegment mem, int offset, String value, int maxLength) static voidwriteVector2f(MemorySegment mem, int offset, org.joml.Vector2fc v) static voidwriteVector3f(MemorySegment mem, int offset, org.joml.Vector3fc v) static voidwriteVector4f(MemorySegment mem, int offset, org.joml.Vector4fc v)
-
Field Details
-
FRAME_HEADER_SIZE
public static final int FRAME_HEADER_SIZEHeader size for framed packets (4 bytes for packet ID).- See Also:
-
PACKET_HEADER_SIZE
public static final int PACKET_HEADER_SIZEPacket header size, 4 bytes for id, 4 bytes for length- See Also:
-
UTF8
-
ASCII
-
PROTO_BOOL
-
PROTO_BYTE
-
PROTO_SHORT
-
PROTO_INT
-
PROTO_LONG
-
PROTO_FLOAT
-
PROTO_DOUBLE
-
UUID_LONG
-
ZERO_VECTOR2
public static final org.joml.Vector2fc ZERO_VECTOR2 -
ZERO_VECTOR3
public static final org.joml.Vector3fc ZERO_VECTOR3 -
ZERO_VECTOR4
public static final org.joml.Vector4fc ZERO_VECTOR4 -
ZERO_QUATERNION
public static final org.joml.Quaternionfc ZERO_QUATERNION -
ZERO_MATRIX
public static final org.joml.Matrix4fc ZERO_MATRIX
-
-
Method Details
-
readBytes
@Nonnull public static byte[] readBytes(@Nonnull io.netty.buffer.ByteBuf buf, int offset, int length) -
readFixedAsciiString
@Nonnull public static String readFixedAsciiString(@Nonnull io.netty.buffer.ByteBuf buf, int offset, int length) -
readFixedString
@Nonnull public static String readFixedString(@Nonnull io.netty.buffer.ByteBuf buf, int offset, int length) -
readFixedAsciiString
@Nonnull public static String readFixedAsciiString(@Nonnull MemorySegment mem, int offset, int length) -
readFixedString
-
readVarString
-
readVarString
-
readValidatedAsciiString
@Nonnull public static String readValidatedAsciiString(@Nonnull io.netty.buffer.ByteBuf buf, int offset, int length, @Nonnull String fieldName) Reads bytes from the buffer, validates they are ASCII (0-127), and returns the decoded string. Combines validation and reading in a single pass over the bytes.- Throws:
ProtocolException- if any byte is outside the ASCII range
-
readVarString
@Nonnull public static String readVarString(String fieldName, @Nonnull MemorySegment mem, int offset, int minLength, int maxLength) -
readVarString
@Nonnull public static String readVarString(String fieldName, @Nonnull MemorySegment mem, int offset, int minLength, int maxLength, long packed) The packed parameter is the VarInt.getWithLength result for offset, so a caller that already decoded the prefix does not decode it twice. -
isWellFormedUtf8
public static boolean isWellFormedUtf8(@Nonnull byte[] bytes) Table 3-7 of the Unicode standard. Decoding substitutes U+FFFD rather than rejecting, and Java and .NET disagree on how many it substitutes for one ill-formed sequence, so neither the decoded length nor a re-encoded length is a portable test. Both decode walks have to accept exactly the same bytes, or one end rejects a payload the other end accepted. -
readVarString
@Nonnull public static String readVarString(String fieldName, @Nonnull MemorySegment mem, int offset, int maxLength) -
readValidatedAsciiString
@Nonnull public static String readValidatedAsciiString(String fieldName, @Nonnull MemorySegment mem, int offset, int minLength, int maxLength) Reads a length-prefixed ASCII string from a MemorySegment, validating every byte is in the ASCII range (0-127). MirrorsreadValidatedAsciiString(ByteBuf, int, int, String)so FFM-emitted readers reject non-ASCII payloads instead of silently replacing bytes with?viaStandardCharsets.US_ASCII. -
readValidatedAsciiString
@Nonnull public static String readValidatedAsciiString(String fieldName, @Nonnull MemorySegment mem, int offset, int minLength, int maxLength, long packed) The packed parameter is the VarInt.getWithLength result for offset, so a caller that already decoded the prefix does not decode it twice. -
readValidatedAsciiString
@Nonnull public static String readValidatedAsciiString(String fieldName, @Nonnull MemorySegment mem, int offset, int maxLength) -
requireFinite
Returnsvalueif it is finite (not NaN and not infinite), otherwise throws aProtocolException. Apply to anyfloatfield that must carry only valid finite wire values. -
requireFinite
Returnsvalueif it is finite, otherwise throws. SeerequireFinite(float, String). -
isFinite
public static boolean isFinite(float value) True ifvalueis finite. No-throw counterpart ofrequireFinite(float, String), used by the structural validator. -
isFinite
public static boolean isFinite(double value) True ifvalueis finite. No-throw counterpart ofrequireFinite(double, String), used by the structural validator. -
isFinite
public static boolean isFinite(@Nonnull org.joml.Vector2fc v) True if every component ofvis finite. -
isFinite
public static boolean isFinite(@Nonnull org.joml.Vector3fc v) True if every component ofvis finite. -
isFinite
public static boolean isFinite(@Nonnull org.joml.Vector4fc v) True if every component ofvis finite. -
isFinite
public static boolean isFinite(@Nonnull org.joml.Quaternionfc q) True if every component ofqis finite. -
isFinite
public static boolean isFinite(@Nonnull org.joml.Matrix4fc m) True if every one of the 16 components ofmis finite. -
requireFinite
@Nonnull public static org.joml.Vector2fc requireFinite(@Nonnull org.joml.Vector2fc v, @Nonnull String fieldName) Returnsvif every component is finite, otherwise throws. Composite counterpart ofrequireFinite(float, String). -
requireFinite
@Nonnull public static org.joml.Vector3fc requireFinite(@Nonnull org.joml.Vector3fc v, @Nonnull String fieldName) Returnsvif every component is finite, otherwise throws. Composite counterpart ofrequireFinite(float, String). -
requireFinite
@Nonnull public static org.joml.Vector4fc requireFinite(@Nonnull org.joml.Vector4fc v, @Nonnull String fieldName) Returnsvif every component is finite, otherwise throws. Composite counterpart ofrequireFinite(float, String). -
requireFinite
@Nonnull public static org.joml.Quaternionfc requireFinite(@Nonnull org.joml.Quaternionfc q, @Nonnull String fieldName) Returnsqif every component is finite, otherwise throws. Composite counterpart ofrequireFinite(float, String). -
requireFinite
@Nonnull public static org.joml.Matrix4fc requireFinite(@Nonnull org.joml.Matrix4fc m, @Nonnull String fieldName) Returnsmif every component is finite, otherwise throws. Composite counterpart ofrequireFinite(float, String). -
utf8ByteLength
Compute the number of UTF-8 bytes needed to encode a string. This avoids actually encoding the string just to get its byte count. -
stringSize
Compute the total wire size of a VarInt-prefixed UTF-8 string. This is VarInt.size(byteLength) + byteLength, computed without double-encoding. -
writeFixedAsciiString
public static void writeFixedAsciiString(@Nonnull io.netty.buffer.ByteBuf buf, @Nullable String value, int length) -
writeFixedString
public static void writeFixedString(@Nonnull io.netty.buffer.ByteBuf buf, @Nullable String value, int length) -
writeVarString
public static void writeVarString(@Nonnull io.netty.buffer.ByteBuf buf, @Nonnull String value, int maxLength) -
writeVarAsciiString
public static void writeVarAsciiString(@Nonnull io.netty.buffer.ByteBuf buf, @Nonnull String value, int maxLength) -
writeVarString
public static int writeVarString(@Nonnull MemorySegment mem, int offset, @Nonnull String value, int maxLength) -
writeVarAsciiString
public static int writeVarAsciiString(@Nonnull MemorySegment mem, int offset, @Nonnull String value, int maxLength) -
readVector2f
-
readVector3f
-
readVector4f
-
readQuaternionf
-
writeVector2f
public static void writeVector2f(@Nonnull MemorySegment mem, int offset, @Nonnull org.joml.Vector2fc v) -
writeVector3f
public static void writeVector3f(@Nonnull MemorySegment mem, int offset, @Nonnull org.joml.Vector3fc v) -
writeVector4f
public static void writeVector4f(@Nonnull MemorySegment mem, int offset, @Nonnull org.joml.Vector4fc v) -
writeQuaternionf
public static void writeQuaternionf(@Nonnull MemorySegment mem, int offset, @Nonnull org.joml.Quaternionfc q) -
writeFixedAsciiString
public static void writeFixedAsciiString(@Nonnull MemorySegment mem, int offset, @Nullable String value, int length) -
writeFixedString
public static void writeFixedString(@Nonnull MemorySegment mem, int offset, @Nullable String value, int length) -
readUUID
-
writeUUID
-
readUUID
-
writeUUID
-
halfToFloat
public static float halfToFloat(short half) -
floatToHalf
public static short floatToHalf(float f) -
writeFramedPacket
public static void writeFramedPacket(@Nonnull Packet packet, @Nonnull Class<? extends Packet> packetClass, @Nonnull io.netty.buffer.ByteBuf out, @Nonnull io.netty.buffer.ByteBufAllocator allocator, @Nonnull PacketStatsRecorder statsRecorder) Write a packet with framing, using an explicit packet class for registry lookup. This is needed for CachedPacket where the actual class differs from the registered type. Wire format: [4-byte payload length] [4-byte packet ID] [payload]- Parameters:
packet- the packet to writepacketClass- the class to use for registry lookupout- the ByteBuf to write toallocator- the buffer allocator to use for temporary buffersstatsRecorder- the recorder for capturing packet statistics
-
writeFramedPacketWithInfo
public static void writeFramedPacketWithInfo(@Nonnull Packet packet, @Nonnull PacketRegistry.PacketInfo info, @Nonnull io.netty.buffer.ByteBuf out, @Nonnull io.netty.buffer.ByteBufAllocator allocator, @Nonnull PacketStatsRecorder statsRecorder) -
readFramedPacket
@Nonnull public static Packet readFramedPacket(@Nonnull io.netty.buffer.ByteBuf in, int payloadLength, @Nonnull io.netty.buffer.ByteBufAllocator allocator, @Nonnull PacketStatsRecorder statsRecorder) Read a framed packet from a ByteBuf. The buffer should be positioned at the packet ID (after the length prefix has been consumed). Handles decompression based on packet definition. Wire format: [4-byte payload length] [4-byte packet ID] [payload]- Parameters:
in- the ByteBuf positioned at packet IDpayloadLength- the payload length (not including packet ID)allocator- the buffer allocator to use for decompression buffersstatsRecorder- the recorder for capturing packet statistics- Returns:
- the deserialized packet, or null if packet ID is unknown
-
readFramedPacketWithInfo
@Nonnull public static Packet readFramedPacketWithInfo(@Nonnull io.netty.buffer.ByteBuf in, int payloadLength, @Nonnull io.netty.buffer.ByteBufAllocator allocator, @Nonnull PacketRegistry.PacketInfo info, @Nonnull PacketStatsRecorder statsRecorder) Read a framed packet with pre-validated PacketInfo (packet ID and size already validated). Used by PacketDecoder for fail-fast validation - packet ID is validated before waiting for payload.- Parameters:
in- the ByteBuf positioned at payload start (after packet ID)payloadLength- the payload length (already validated against info.maxSize())allocator- the buffer allocator to use for decompression buffersinfo- the pre-validated packet infostatsRecorder- the recorder for capturing packet statistics- Returns:
- the deserialized packet
-
writeFramedPacket
public static int writeFramedPacket(@Nonnull MemorySegment compressionContext, @Nonnull Packet packet, @Nonnull PacketRegistry.PacketInfo packetInfo, @Nonnull MemorySegment out, int offset, int packetSize, @Nonnull PacketStatsRecorder statsRecorder) -
readFramedPacket
@Nonnull public static Packet readFramedPacket(@Nonnull MemorySegment decompressionContext, @Nonnull MemorySegment in, int payloadLength, @Nonnull PacketStatsRecorder statsRecorder) -
readFramedPacketWithInfo
@Nonnull public static Packet readFramedPacketWithInfo(@Nonnull MemorySegment decompressionContext, @Nonnull MemorySegment in, int offset, int payloadLength, @Nonnull PacketRegistry.PacketInfo info, @Nonnull PacketStatsRecorder statsRecorder)
-