Class RegularPacketReader

java.lang.Object
naga.packetreader.RegularPacketReader
All Implemented Interfaces:
PacketReader

public class RegularPacketReader extends Object implements PacketReader
Reads packet of the format
 [header 1-4 bytes] → content size
 [content] → 0-255/0-65535/0-16777215/0-2147483646
 

Note that the maximum size for 4 bytes is a signed 32 bit int, not unsigned.

Author:
Christoffer Lerno
  • Constructor Details

    • RegularPacketReader

      public RegularPacketReader(int headerSize, boolean bigEndian)
      Creates a regular packet reader with the given header size.
      Parameters:
      headerSize - the header size, 1 - 4 bytes.
      bigEndian - big endian (largest byte first) or little endian (smallest byte first)
  • Method Details

    • nextPacket

      public byte[] nextPacket(ByteBuffer byteBuffer) throws ProtocolViolationException
      Description copied from interface: PacketReader
      Create a new packet using the ByteBuffer given.

      If there isn't sufficient data to construct a packet, return null.

      Specified by:
      nextPacket in interface PacketReader
      Parameters:
      byteBuffer - the byte buffer to use.
      Returns:
      the new packet created, or null if no packet could be created. The method will continously be called until nextPacket returns null.
      Throws:
      ProtocolViolationException - is there was an error constructing the packet.