Class RegularPacketReader

  • All Implemented Interfaces:
    PacketReader

    public class RegularPacketReader
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      RegularPacketReader​(int headerSize, boolean bigEndian)
      Creates a regular packet reader with the given header size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] nextPacket​(java.nio.ByteBuffer byteBuffer)
      Create a new packet using the ByteBuffer given.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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 Detail

      • nextPacket

        public byte[] nextPacket​(java.nio.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.