Class ReadablePacket<T extends Client<Connection<T>>>

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class ReadablePacket<T extends Client<Connection<T>>>
    extends java.lang.Object
    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 
      Modifier and Type Field Description
      protected T client  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ReadablePacket()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected int available()  
      T getClient()  
      protected abstract boolean read()  
      protected boolean readBoolean()
      Reads byte from the buffer
      protected byte readByte()
      Reads raw byte from the buffer
      protected void readBytes​(byte[] dst)
      Reads as many bytes as the length of the array.
      protected void readBytes​(byte[] dst, int offset, int length)
      Reads as many bytes as the given length (len).
      protected char readChar()
      Reads char from the buffer
      protected double readDouble()
      Reads double from the buffer.
      protected float readFloat()
      Reads float from the buffer.
      protected int readInt()
      Reads int from the buffer.
      protected boolean readIntAsBoolean()
      Reads int from the buffer.
      protected long readLong()
      Reads long from the buffer.
      protected short readShort()
      Reads short from the buffer.
      protected boolean readShortAsBoolean()
      Reads short from the buffer.
      protected java.lang.String readSizedString()
      Reads a predefined length String from the buffer.
      protected java.lang.String readString()
      Reads String from the buffer.
      protected int readUnsignedByte()
      Reads byte from the buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Runnable

        run
    • Constructor Detail

      • ReadablePacket

        protected ReadablePacket()
    • 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()