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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the size of the header's length value.
    int
    getLengthSize(int length)
    Gets the size of the header's length value.
    boolean
    Gets whether the header's length value can vary in size.
    int
    readLength(io.netty.buffer.ByteBuf buf, int available)
    Reads the length of a packet from the given input.
    int
    readPacketId(io.netty.buffer.ByteBuf buf)
    Reads the ID of a packet from the given input.
    void
    writeLength(io.netty.buffer.ByteBuf buf, int length)
    Writes the length of a packet to the given output.
    void
    writePacketId(io.netty.buffer.ByteBuf buf, int packetId)
    Writes the ID of a packet to the given output.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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, 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.
      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: PacketHeader
      Writes the length of a packet to the given output.
      Specified by:
      writeLength in interface PacketHeader
      Parameters:
      buf - Buffer to write to.
      length - Length to write.
    • readPacketId

      public int readPacketId(io.netty.buffer.ByteBuf buf)
      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.
      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: PacketHeader
      Writes the ID of a packet to the given output.
      Specified by:
      writePacketId in interface PacketHeader
      Parameters:
      buf - Buffer to write to.
      packetId - Packet ID to write.