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, PacketCodecHelper codecHelper, int available) Reads the length of a packet from the given input.intreadPacketId(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper) Reads the ID of a packet from the given input.voidwriteLength(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int length) Writes the length of a packet to the given output.voidwritePacketId(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, 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
Reads the length of a packet from the given input.- Parameters:
buf- Buffer to read from.codecHelper- The codec helper.available- Number of packet bytes available after the length.- Returns:
- The resulting packet length.
-
writeLength
Writes the length of a packet to the given output.- Parameters:
buf- Buffer to write to.codecHelper- The codec helper.length- Length to write.
-
readPacketId
Reads the ID of a packet from the given input.- Parameters:
buf- Buffer to read from.codecHelper- The codec helper.- Returns:
- The resulting packet ID, or -1 if the packet should not be read yet.
-
writePacketId
Writes the ID of a packet to the given output.- Parameters:
buf- Buffer to write to.codecHelper- The codec helper.packetId- Packet ID to write.
-