Class ByteBufPacketReader

java.lang.Object
crow.game.codec.netty.ByteBufPacketReader
All Implemented Interfaces:
PacketReader

public class ByteBufPacketReader extends Object implements PacketReader
Implementation of PacketReader that wraps a Netty ByteBuf.
  • Constructor Details

    • ByteBufPacketReader

      public ByteBufPacketReader(io.netty.buffer.ByteBuf buf, int size)
  • Method Details

    • readInetAddressAndPort

      public InetAddressAndPort readInetAddressAndPort() throws UnknownHostException
      Description copied from interface: PacketReader
      Reads the address and port pair from the kro server byte stream, which is a 6-byte series.
      Specified by:
      readInetAddressAndPort in interface PacketReader
      Returns:
      The IP address and port pair
      Throws:
      UnknownHostException
      See Also:
    • skip

      public void skip(int length)
      Description copied from interface: PacketReader
      Skip N bytes
      Specified by:
      skip in interface PacketReader
      Parameters:
      length - number of bytes to skip
    • readString

      public String readString(int length)
      Description copied from interface: PacketReader
      Reads the next N bytes as a string.

      NOTE:Strings in KRO are 0-terminated and use pre-determined lengths. So "hello" of length 20 will be "hello" 0x0 0x0 0x0...

      Specified by:
      readString in interface PacketReader
      Parameters:
      length - the size of the string, with zero padding.
      Returns:
      The string object.
    • readBytes

      public byte[] readBytes(int length)
      Specified by:
      readBytes in interface PacketReader
    • readIntLE

      public int readIntLE()
      Specified by:
      readIntLE in interface PacketReader
      Returns:
      the next 4-byte integer in the stream
    • readShortLE

      public short readShortLE()
      Specified by:
      readShortLE in interface PacketReader
      Returns:
      the next 4-byte short in the stream
    • readByte

      public byte readByte()
      Specified by:
      readByte in interface PacketReader
      Returns:
      the next byte in the stream
    • getUnderlyingObject

      public <T> T getUnderlyingObject()
      Specified by:
      getUnderlyingObject in interface PacketReader
      Type Parameters:
      T - The underlying object type.
      Returns:
      The underlying object that backs this packet reader, usually a byte buffer.
    • size

      public int size()
      Specified by:
      size in interface PacketReader
      Returns:
      the size of the packet
    • readLongLE

      public long readLongLE()
      Specified by:
      readLongLE in interface PacketReader