Package crow.game.codec.netty
Class ByteBufPacketReader
java.lang.Object
crow.game.codec.netty.ByteBufPacketReader
- All Implemented Interfaces:
PacketReader
Implementation of PacketReader that wraps a Netty
ByteBuf.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TbytereadByte()byte[]readBytes(int length) Reads the address and port pair from the kro server byte stream, which is a 6-byte series.intlongshortreadString(int length) Reads the next N bytes as a string.intsize()voidskip(int length) Skip N bytes
-
Constructor Details
-
ByteBufPacketReader
public ByteBufPacketReader(io.netty.buffer.ByteBuf buf, int size)
-
-
Method Details
-
readInetAddressAndPort
Description copied from interface:PacketReaderReads the address and port pair from the kro server byte stream, which is a 6-byte series.- Specified by:
readInetAddressAndPortin interfacePacketReader- Returns:
- The IP address and port pair
- Throws:
UnknownHostException- See Also:
-
skip
public void skip(int length) Description copied from interface:PacketReaderSkip N bytes- Specified by:
skipin interfacePacketReader- Parameters:
length- number of bytes to skip
-
readString
Description copied from interface:PacketReaderReads the next N bytes as a string.NOTE:Strings in KRO are 0-terminated and use pre-determined lengths. So "hello" of length 20 will be "hello" 0x0 0x0 0x0...
- Specified by:
readStringin interfacePacketReader- Parameters:
length- the size of the string, with zero padding.- Returns:
- The string object.
-
readBytes
public byte[] readBytes(int length) - Specified by:
readBytesin interfacePacketReader
-
readIntLE
public int readIntLE()- Specified by:
readIntLEin interfacePacketReader- Returns:
- the next 4-byte integer in the stream
-
readShortLE
public short readShortLE()- Specified by:
readShortLEin interfacePacketReader- Returns:
- the next 4-byte short in the stream
-
readByte
public byte readByte()- Specified by:
readBytein interfacePacketReader- Returns:
- the next byte in the stream
-
getUnderlyingObject
public <T> T getUnderlyingObject()- Specified by:
getUnderlyingObjectin interfacePacketReader- Type Parameters:
T- The underlying object type.- Returns:
- The underlying object that backs this packet reader, usually a byte buffer.
-
size
public int size()- Specified by:
sizein interfacePacketReader- Returns:
- the size of the packet
-
readLongLE
public long readLongLE()- Specified by:
readLongLEin interfacePacketReader
-