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
int readLength(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int available) throws IOException 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.
- Throws:
IOException- If an I/O error occurs.
-
writeLength
void writeLength(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int length) throws IOException Writes the length of a packet to the given output.- Parameters:
buf- Buffer to write to.codecHelper- The codec helper.length- Length to write.- Throws:
IOException- If an I/O error occurs.
-
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.
- Throws:
IOException- If an I/O error occurs.
-
writePacketId
void writePacketId(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int packetId) throws IOException 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.- Throws:
IOException- If an I/O error occurs.
-