Package com.kraken.api.core.packet
Class PacketBufferReader
- java.lang.Object
-
- com.kraken.api.core.packet.PacketBufferReader
-
public class PacketBufferReader extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description PacketBufferReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringdecodeStringCp1252(byte[] data, int startIndex, int endIndex)Decodes a byte array range from CP1252 encoding back to a Java String.static intreadByte(byte[] data, int pos)Reads a single byte from the array at the given position.static intreadInt(byte[] data, int pos)Reads an integer from the byte array at the given position.static PacketDatareadPacketBuffer(java.lang.Object packetBufferNode)Reads the raw byte data from a packet buffer node using reflection.static intreadShort(byte[] data, int pos)Reads a short from the byte array at the given position.static java.lang.StringreadStringCp1252NullCircumfixed(byte[] data, int startPos)Reads a CP1252 null-circumfixed string from the byte array.static java.lang.StringreadStringCp1252NullTerminated(byte[] data, int startPos)Reads a CP1252 null-terminated string from the byte array.static java.lang.StringtoHexString(byte[] bytes)Converts byte array to hex string for display.
-
-
-
Method Detail
-
readPacketBuffer
public static PacketData readPacketBuffer(java.lang.Object packetBufferNode)
Reads the raw byte data from a packet buffer node using reflection.- Parameters:
packetBufferNode- The object containing the packet buffer field.- Returns:
- A
PacketDataobject containing the extracted bytes;
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
Converts byte array to hex string for display.- Parameters:
bytes- The byte array to convert.- Returns:
- A formatted hex string with spaces and newlines every 16 bytes.
-
readInt
public static int readInt(byte[] data, int pos)Reads an integer from the byte array at the given position.- Parameters:
data- The byte array.pos- The starting index (expects 4 bytes available).- Returns:
- The 32-bit integer value, or 0 if the position is out of bounds.
-
readShort
public static int readShort(byte[] data, int pos)Reads a short from the byte array at the given position.- Parameters:
data- The byte array.pos- The starting index (expects 2 bytes available).- Returns:
- The 16-bit value as an integer, or 0 if out of bounds.
-
readByte
public static int readByte(byte[] data, int pos)Reads a single byte from the array at the given position.- Parameters:
data- The byte array.pos- The index to read.- Returns:
- The unsigned byte value as an integer, or 0 if out of bounds.
-
readStringCp1252NullTerminated
public static java.lang.String readStringCp1252NullTerminated(byte[] data, int startPos)Reads a CP1252 null-terminated string from the byte array. Format: [string bytes][0x00]- Parameters:
data- The byte array.startPos- The starting position in the array.- Returns:
- The decoded string.
-
readStringCp1252NullCircumfixed
public static java.lang.String readStringCp1252NullCircumfixed(byte[] data, int startPos)Reads a CP1252 null-circumfixed string from the byte array. Format: [0x00][string bytes][0x00]- Parameters:
data- The byte array.startPos- The starting position (should be at the leading null byte).- Returns:
- The decoded string.
-
decodeStringCp1252
public static java.lang.String decodeStringCp1252(byte[] data, int startIndex, int endIndex)Decodes a byte array range from CP1252 encoding back to a Java String. This reverses the encodeStringCp1252 method.- Parameters:
data- The byte array containing CP1252 encoded data.startIndex- The starting index in the array.endIndex- The ending index (exclusive).- Returns:
- The decoded string.
-
-