Class DefaultPacketHeader
java.lang.Object
org.geysermc.mcprotocollib.network.packet.DefaultPacketHeader
- All Implemented Interfaces:
PacketHeader
The default packet header, using a varint packet length and id.
-
Constructor Summary
Constructors -
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.
-
Constructor Details
-
DefaultPacketHeader
public DefaultPacketHeader()
-
-
Method Details
-
isLengthVariable
public boolean isLengthVariable()Description copied from interface:PacketHeaderGets whether the header's length value can vary in size.- Specified by:
isLengthVariablein interfacePacketHeader- Returns:
- Whether the header's length value can vary in size.
-
getLengthSize
public int getLengthSize()Description copied from interface:PacketHeaderGets the size of the header's length value.- Specified by:
getLengthSizein interfacePacketHeader- Returns:
- The length value's size.
-
getLengthSize
public int getLengthSize(int length) Description copied from interface:PacketHeaderGets the size of the header's length value.- Specified by:
getLengthSizein interfacePacketHeader- Parameters:
length- Length value to get the size of.- Returns:
- The length value's size.
-
readLength
Description copied from interface:PacketHeaderReads the length of a packet from the given input.- Specified by:
readLengthin interfacePacketHeader- 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
Description copied from interface:PacketHeaderWrites the length of a packet to the given output.- Specified by:
writeLengthin interfacePacketHeader- Parameters:
buf- Buffer to write to.codecHelper- The codec helper.length- Length to write.
-
readPacketId
Description copied from interface:PacketHeaderReads the ID of a packet from the given input.- Specified by:
readPacketIdin interfacePacketHeader- 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
Description copied from interface:PacketHeaderWrites the ID of a packet to the given output.- Specified by:
writePacketIdin interfacePacketHeader- Parameters:
buf- Buffer to write to.codecHelper- The codec helper.packetId- Packet ID to write.
-