Interface PacketHeader
- All Known Implementing Classes:
DefaultPacketHeader
public interface PacketHeader
The header of a protocol's packets.
-
Method Summary
Modifier and TypeMethodDescriptionintGets the size of the header's length value.intgetLengthSize(int length) Gets the size of the header's length value.booleanGets whether the header's length value can vary in size.intreadLength(io.netty.buffer.ByteBuf buf, int available) Reads the length of a packet from the given input.intreadPacketId(io.netty.buffer.ByteBuf buf) Reads the ID of a packet from the given input.voidwriteLength(io.netty.buffer.ByteBuf buf, int length) Writes the length of a packet to the given output.voidwritePacketId(io.netty.buffer.ByteBuf buf, int packetId) Writes the ID of a packet to the given output.
-
Method Details
-
isLengthVariable
boolean isLengthVariable()Gets whether the header's length value can vary in size.- Returns:
- Whether the header's length value can vary in size.
-
getLengthSize
int getLengthSize()Gets the size of the header's length value.- Returns:
- The length value's size.
-
getLengthSize
int getLengthSize(int length) Gets the size of the header's length value.- Parameters:
length- Length value to get the size of.- Returns:
- The length value's size.
-
readLength
int readLength(io.netty.buffer.ByteBuf buf, int available) Reads the length of a packet from the given input.- Parameters:
buf- Buffer to read from.available- Number of packet bytes available after the length.- Returns:
- The resulting packet length.
-
writeLength
void writeLength(io.netty.buffer.ByteBuf buf, int length) Writes the length of a packet to the given output.- Parameters:
buf- Buffer to write to.length- Length to write.
-
readPacketId
int readPacketId(io.netty.buffer.ByteBuf buf) Reads the ID of a packet from the given input.- Parameters:
buf- Buffer to read from.- Returns:
- The resulting packet ID, or -1 if the packet should not be read yet.
-
writePacketId
void writePacketId(io.netty.buffer.ByteBuf buf, int packetId) Writes the ID of a packet to the given output.- Parameters:
buf- Buffer to write to.packetId- Packet ID to write.
-