Package io.github.joealisson.mmocore
Class WritablePacket<T extends Client<Connection<T>>>
- java.lang.Object
-
- io.github.joealisson.mmocore.AbstractPacket<T>
-
- io.github.joealisson.mmocore.WritablePacket<T>
-
public abstract class WritablePacket<T extends Client<Connection<T>>> extends AbstractPacket<T>
This class represents a Packet that can be sent to clients. All data sent 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 protectedWritablePacket()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intpacketSize()By default this method return the size of the bufferSize configured.protected abstract booleanwrite()Writes the data into the packetprotected voidwriteByte(boolean value)Write boolean to the buffer.protected voidwriteByte(byte value)Write abyte to the buffer.protected voidwriteByte(int value)Write a int to the buffer, the int is casted to a byte;protected voidwriteBytes(byte[] bytes)Write byte[] to the buffer.protected voidwriteChar(char value)Write char to the buffer.
16 bit charprotected voidwriteDouble(double value)Write double to the buffer.protected voidwriteFloat(float value)Write float to the buffer.protected voidwriteInt(boolean value)Write boolean to the buffer.protected voidwriteInt(int value)Write int to the buffer.protected voidwriteLong(long value)Write long to the buffer.protected voidwriteShort(boolean value)Write boolean to the buffer.protected voidwriteShort(int value)Write short to the buffer.protected voidwriteSizedString(java.lang.CharSequence text)Write String to the buffer preceded by a short 16 bit with String length and no null termination.protected voidwriteString(java.lang.CharSequence text)Write a String to the buffer with a null termination (\000).-
Methods inherited from class io.github.joealisson.mmocore.AbstractPacket
getClient
-
-
-
-
Method Detail
-
writeByte
protected final void writeByte(byte value)
Write abyte to the buffer.
8bit integer (00) If the underlying data array can't hold a new byte its size is increased 20%- Parameters:
value- to be written
-
writeByte
protected final void writeByte(int value)
Write a int to the buffer, the int is casted to a byte;- Parameters:
value- to be written
-
writeByte
protected final void writeByte(boolean value)
Write boolean to the buffer.
If the value is true so write a byte with value 1, otherwise 0 8bit integer (00)- Parameters:
value- to be written
-
writeDouble
protected final void writeDouble(double value)
Write double to the buffer.
64bit double precision float (00 00 00 00 00 00 00 00)- Parameters:
value- to be written
-
writeShort
protected final void writeShort(int value)
Write short to the buffer.
16bit integer (00 00)- Parameters:
value- to be written
-
writeShort
protected final void writeShort(boolean value)
Write boolean to the buffer.
If the value is true so write a byte with value 1, otherwise 0 16bit integer (00 00)- Parameters:
value- to be written
-
writeInt
protected final void writeInt(int value)
Write int to the buffer.
32bit integer (00 00 00 00)- Parameters:
value- to be written
-
writeInt
protected final void writeInt(boolean value)
Write boolean to the buffer.
If the value is true so write a byte with value 1, otherwise 0 32bit integer (00 00 00 00)- Parameters:
value- to be written
-
writeFloat
protected final void writeFloat(float value)
Write float to the buffer.
32bit float point number (00 00 00 00)- Parameters:
value- to be written
-
writeLong
protected final void writeLong(long value)
Write long to the buffer.
64bit integer (00 00 00 00 00 00 00 00)- Parameters:
value- to be written
-
writeBytes
protected final void writeBytes(byte[] bytes)
Write byte[] to the buffer.
8bit integer array (00 ...)- Parameters:
bytes- to be written
-
writeChar
protected final void writeChar(char value)
Write char to the buffer.
16 bit char- Parameters:
value- the char to be put on data.
-
writeString
protected final void writeString(java.lang.CharSequence text)
Write a String to the buffer with a null termination (\000). Each character is a 16bit char- Parameters:
text- to be written
-
writeSizedString
protected final void writeSizedString(java.lang.CharSequence text)
Write String to the buffer preceded by a short 16 bit with String length and no null termination. Each character is a 16bit char.- Parameters:
text- to be written
-
packetSize
protected int packetSize()
By default this method return the size of the bufferSize configured. If the size of the packet can be calculated, its high recommended to override this method to return the exactly packet size. This way less resource are used a each packet improving the memory and cpu usage.- Returns:
- The size of the packet to be sent.
-
write
protected abstract boolean write()
Writes the data into the packet- Returns:
- the packet was written successful
-
-