Class PacketPreCodec


  • public class PacketPreCodec
    extends Object
    This class is used to prehandle the packet.
    • Constructor Detail

      • PacketPreCodec

        public PacketPreCodec()
    • Method Detail

      • readInt

        public int readInt()
        Read a integer
        Returns:
        the integer read from precodec
      • readLong

        public long readLong()
        Read a long
        Returns:
        the long read from precodec
      • writeInt

        public void writeInt​(int v)
        Write a integer
        Parameters:
        v - the integer
      • writeLong

        public void writeLong​(long v)
        Write a long
        Parameters:
        v - the long
      • writeString

        public void writeString​(String v)
        Write a string
        Parameters:
        v - the string
      • readString

        public String readString()
        Read a string
        Returns:
        the string read from precodec
      • writeFloat

        public void writeFloat​(float v)
        Write a float
        Parameters:
        v - the float
      • readFloat

        public float readFloat()
        Read a float
        Returns:
        the float read from precodec
      • writeDouble

        public void writeDouble​(double v)
        Write a double
        Parameters:
        v - the double
      • readDouble

        public double readDouble()
        Read a double
        Returns:
        the double read from precodec
      • readByte

        public byte readByte()
        Read a byte
        Returns:
        the byte read from precodec
      • writeByte

        public void writeByte​(byte b)
        Write a byte
        Parameters:
        b - the byte
      • readShort

        public short readShort()
        Read a short
        Returns:
        the short read from precodec
      • writeShort

        public void writeShort​(short v)
        Write a short
        Parameters:
        v - the short
      • getBytes

        public byte[] getBytes()
        Get all bytes of the packet
        Returns:
        all bytes of the packet
      • readPacket

        @Nullable
        public Packet readPacket()
        Read a packet
        Returns:
        the packet read from precodec
      • writePacket

        public <T extends Packet> boolean writePacket​(T packet)
        Write a packet
        Type Parameters:
        T - the packet type
        Parameters:
        packet - the packet
        Returns:
        true if the packet has been written successfully, false otherwise
      • registerPacketCodec

        public static <T extends Packet> void registerPacketCodec​(int packetId,
                                                                  PacketCodec<T> packetCodec)
        Register the packet codec for the special packet id
        Type Parameters:
        T - the packet type
        Parameters:
        packetId - the packet id
        packetCodec - the packet codec
      • push

        public void push​(byte[] buffer,
                         int offset,
                         int length)
        Push the data to the precodec
        Parameters:
        buffer - the data
        offset - the offset of the data
        length - the length of the data
        See Also:
        push(byte[], int)
      • push

        public void push​(byte[] buffer,
                         int length)
        Push the data to the precodec
        Parameters:
        buffer - the data
        length - the length of the data
        See Also:
        push(byte[], int, int)