naga.packetreader
public class RegularPacketReader extends java.lang.Object implements PacketReader
[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.
Constructor and Description |
---|
RegularPacketReader(int headerSize,
boolean bigEndian)
Creates a regular packet reader with the given header size.
|
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
getBuffer()
Return the next buffer to use.
|
byte[] |
getNextPacket()
Return the next packet or null if no complete packet can be constructed.
|
public RegularPacketReader(int headerSize, boolean bigEndian)
headerSize
- the header size, 1 - 4 bytes.bigEndian
- big endian (largest byte first) or little endian (smallest byte first)public java.nio.ByteBuffer getBuffer() throws ProtocolViolationException
getBuffer
in interface PacketReader
ProtocolViolationException
- if the header was read and the size of the content is
larger or equal to Integer.MAX_VALUE.public byte[] getNextPacket() throws ProtocolViolationException
getNextPacket
in interface PacketReader
ProtocolViolationException
- if the size of the packet is larger or equal to Integer.MAX_VALUE.