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, 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.
-
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
public int readLength(io.netty.buffer.ByteBuf buf, int available) Description copied from interface:PacketHeaderReads the length of a packet from the given input.- Specified by:
readLengthin interfacePacketHeader- Parameters:
buf- Buffer to read from.available- Number of packet bytes available after the length.- Returns:
- The resulting packet length.
-
writeLength
public void writeLength(io.netty.buffer.ByteBuf buf, int length) Description copied from interface:PacketHeaderWrites the length of a packet to the given output.- Specified by:
writeLengthin interfacePacketHeader- Parameters:
buf- Buffer to write to.length- Length to write.
-
readPacketId
public int readPacketId(io.netty.buffer.ByteBuf buf) Description copied from interface:PacketHeaderReads the ID of a packet from the given input.- Specified by:
readPacketIdin interfacePacketHeader- Parameters:
buf- Buffer to read from.- Returns:
- The resulting packet ID, or -1 if the packet should not be read yet.
-
writePacketId
public void writePacketId(io.netty.buffer.ByteBuf buf, int packetId) Description copied from interface:PacketHeaderWrites the ID of a packet to the given output.- Specified by:
writePacketIdin interfacePacketHeader- Parameters:
buf- Buffer to write to.packetId- Packet ID to write.
-