Package naga.packetreader
Class RegularPacketReader
java.lang.Object
naga.packetreader.RegularPacketReader
- All Implemented Interfaces:
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
-
Field Summary
Fields inherited from interface naga.PacketReader
SKIP_PACKET
-
Constructor Summary
ConstructorsConstructorDescriptionRegularPacketReader
(int headerSize, boolean bigEndian) Creates a regular packet reader with the given header size. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
nextPacket
(ByteBuffer byteBuffer) Create a new packet using the ByteBuffer given.
-
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
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.
-