Package io.github.joealisson.mmocore
Class ReadablePacket<T>
- java.lang.Object
-
- io.github.joealisson.mmocore.AbstractPacket<T>
-
- io.github.joealisson.mmocore.ReadablePacket<T>
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
DataWrapper
public abstract class ReadablePacket<T> extends AbstractPacket<T> implements java.lang.Runnable
This class represents a Packet received from the client. All data received must have a header with 2 bytes and an optional payload. The first and second bytes is a 16 bits integer holding the size of the packet.
-
-
Field Summary
-
Fields inherited from class io.github.joealisson.mmocore.AbstractPacket
client
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedReadablePacket()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intavailableData()protected abstract booleanread()protected bytereadByte()Reads raw byte from the bufferprotected voidreadBytes(byte[] dst)Reads as many bytes as the length of the array.protected voidreadBytes(byte[] dst, int offset, int length)Reads as many bytes as the given length (len).protected charreadChar()Reads char from the bufferprotected doublereadDouble()Reads double from the buffer.protected floatreadFloat()Reads float from the buffer.protected intreadInt()Reads int from the buffer.protected longreadLong()Reads long from the buffer.protected shortreadShort()Reads short from the buffer.protected java.lang.StringreadSizedString()Reads a predefined length String from the buffer.protected java.lang.StringreadString()Reads String from the buffer.protected intreadUnsignedByte()Reads byte from the buffer.-
Methods inherited from class io.github.joealisson.mmocore.AbstractPacket
getClient
-
-
-
-
Method Detail
-
availableData
protected final int availableData()
-
readBytes
protected final void readBytes(byte[] dst)
Reads as many bytes as the length of the array.- Parameters:
dst- : the byte array which will be filled with the data.
-
readBytes
protected final void readBytes(byte[] dst, int offset, int length)Reads as many bytes as the given length (len). Starts to fill the byte array from the given offset to offset + len.- Parameters:
dst- : the byte array which will be filled with the data.offset- : starts to fill the byte array from the given offset.length- : the given length of bytes to be read.
-
readByte
protected final byte readByte()
Reads raw byte from the buffer- Returns:
- byte read
-
readChar
protected final char readChar()
Reads char from the buffer- Returns:
- char read
-
readUnsignedByte
protected final int readUnsignedByte()
Reads byte from the buffer.
8bit integer (00)- Returns:
- unsigned int read
-
readShort
protected final short readShort()
Reads short from the buffer.
16bit integer (00 00)- Returns:
- short read
-
readFloat
protected final float readFloat()
Reads float from the buffer.
32bit precision float (00 00 00 00)- Returns:
- float read
-
readInt
protected final int readInt()
Reads int from the buffer.
32bit integer (00 00 00 00)- Returns:
- int read
-
readLong
protected final long readLong()
Reads long from the buffer.
64bit integer (00 00 00 00 00 00 00 00)- Returns:
- long read
-
readDouble
protected final double readDouble()
Reads double from the buffer.
64bit double precision float (00 00 00 00 00 00 00 00)- Returns:
- double read
-
readString
protected final java.lang.String readString()
Reads String from the buffer.- Returns:
- String read
-
readSizedString
protected final java.lang.String readSizedString()
Reads a predefined length String from the buffer.- Returns:
- String read
-
read
protected abstract boolean read()
-
-