Package io.github.joealisson.mmocore
Class ReadablePacket<T extends Client<Connection<T>>>
- java.lang.Object
-
- io.github.joealisson.mmocore.ReadablePacket<T>
-
- All Implemented Interfaces:
java.lang.Runnable
public abstract class ReadablePacket<T extends Client<Connection<T>>> extends java.lang.Object implements java.lang.RunnableThis 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedReadablePacket()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intavailable()TgetClient()protected abstract booleanread()protected booleanreadBoolean()Reads byte from the bufferprotected 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 booleanreadIntAsBoolean()Reads int from the buffer.protected longreadLong()Reads long from the buffer.protected shortreadShort()Reads short from the buffer.protected booleanreadShortAsBoolean()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.
-
-
-
Field Detail
-
client
protected T extends Client<Connection<T>> client
-
-
Method Detail
-
available
protected final int available()
- Returns:
- the available data to be read
-
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
-
readBoolean
protected final boolean readBoolean()
Reads byte from the buffer- Returns:
- true if byte is not equal 0
-
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
-
readShortAsBoolean
protected final boolean readShortAsBoolean()
Reads short from the buffer.
16bit integer (00 00)- Returns:
- true if the short is not equals 0
-
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
-
readIntAsBoolean
protected final boolean readIntAsBoolean()
Reads int from the buffer.
32bit integer (00 00 00 00)- Returns:
- true if int is not equals 0
-
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
-
getClient
public T getClient()
-
read
protected abstract boolean read()
-
-