Class DefaultPacketHeader

java.lang.Object
org.geysermc.mcprotocollib.network.packet.DefaultPacketHeader
All Implemented Interfaces:
PacketHeader

public class DefaultPacketHeader extends Object implements PacketHeader
The default packet header, using a varint packet length and id.
  • Constructor Details

    • DefaultPacketHeader

      public DefaultPacketHeader()
  • Method Details

    • isLengthVariable

      public boolean isLengthVariable()
      Description copied from interface: PacketHeader
      Gets whether the header's length value can vary in size.
      Specified by:
      isLengthVariable in interface PacketHeader
      Returns:
      Whether the header's length value can vary in size.
    • getLengthSize

      public int getLengthSize()
      Description copied from interface: PacketHeader
      Gets the size of the header's length value.
      Specified by:
      getLengthSize in interface PacketHeader
      Returns:
      The length value's size.
    • getLengthSize

      public int getLengthSize(int length)
      Description copied from interface: PacketHeader
      Gets the size of the header's length value.
      Specified by:
      getLengthSize in interface PacketHeader
      Parameters:
      length - Length value to get the size of.
      Returns:
      The length value's size.
    • readLength

      public int readLength(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int available)
      Description copied from interface: PacketHeader
      Reads the length of a packet from the given input.
      Specified by:
      readLength in interface PacketHeader
      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

      public void writeLength(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int length)
      Description copied from interface: PacketHeader
      Writes the length of a packet to the given output.
      Specified by:
      writeLength in interface PacketHeader
      Parameters:
      buf - Buffer to write to.
      codecHelper - The codec helper.
      length - Length to write.
    • readPacketId

      public int readPacketId(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper)
      Description copied from interface: PacketHeader
      Reads the ID of a packet from the given input.
      Specified by:
      readPacketId in interface PacketHeader
      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

      public void writePacketId(io.netty.buffer.ByteBuf buf, PacketCodecHelper codecHelper, int packetId)
      Description copied from interface: PacketHeader
      Writes the ID of a packet to the given output.
      Specified by:
      writePacketId in interface PacketHeader
      Parameters:
      buf - Buffer to write to.
      codecHelper - The codec helper.
      packetId - Packet ID to write.