Package naga.packetreader
Class RegularPacketReader
- java.lang.Object
-
- naga.packetreader.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-2147483646Note that the maximum size for 4 bytes is a signed 32 bit int, not unsigned.
- Author:
- Christoffer Lerno
-
-
Field Summary
-
Fields inherited from interface naga.PacketReader
SKIP_PACKET
-
-
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.
-
-
-
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 interfacePacketReader
- 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.
-
-