Record Class PacketRule

java.lang.Object
java.lang.Record
crow.game.codec.PacketRule

public record PacketRule(int minVersion, int maxVersion, short prefix, int data, PacketRule.Type type, String name, Class<?> clz) extends Record
Represents a specification for which packet ID (labeled 'prefix' here) is of what type (STATIC or DYNAMIC), what name and Java class POJO, and what kRO packet version the POJO maps to.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The type of packet, currently only 2.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PacketRule(int minVersion, int maxVersion, short prefix, int data, PacketRule.Type type, String name, Class<?> clz)
    Packet rule constructor.
    PacketRule(short prefix, int data, PacketRule.Type type, Class<?> clz)
    Simpler packet rule constructor.
    PacketRule(short prefix, int data, PacketRule.Type type, String name, Class<?> clz)
    Simpler packet rule constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    clz()
    Returns the value of the clz record component.
    int
    Returns the value of the data record component.
    static PacketRule
    Dynamic(int prefix, int sizeTag, Class<?> clz)
     
    static PacketRule
    Dynamic(short prefix, int sizeTag, Class<?> clz)
    Utility constructor for building a non-packet version specific dynamic packet whose name is derived from the given class.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the maxVersion record component.
    int
    Returns the value of the minVersion record component.
    Returns the value of the name record component.
    short
    Returns the value of the prefix record component.
    static PacketRule
    Static(int prefix, int size, Class<?> clz)
     
    static PacketRule
    Static(short prefix, int size, Class<?> clz)
    Utility constructor for building a non-packet version specific static packet whose name is derived from the given class.
    final String
    Returns a string representation of this record class.
    Returns the value of the type record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PacketRule

      public PacketRule(short prefix, int data, PacketRule.Type type, Class<?> clz)
      Simpler packet rule constructor.
      Parameters:
      prefix - The 2-byte code prefix for matching the packet.
      data - The static or dynamic size tag indicator.
      type - The type of the packet, STATIC or DYNAMIC
      clz - The class of the POJO we are serializing and deserializing.
    • PacketRule

      public PacketRule(short prefix, int data, PacketRule.Type type, String name, Class<?> clz)
      Simpler packet rule constructor.
      Parameters:
      prefix - The 2-byte code prefix for matching the packet.
      data - The static or dynamic size tag indicator.
      type - The type of the packet, STATIC or DYNAMIC
      name - The name of the packet, currently only for logging.
      clz - The class of the POJO we are serializing and deserializing.
    • PacketRule

      public PacketRule(int minVersion, int maxVersion, short prefix, int data, PacketRule.Type type, String name, Class<?> clz)
      Packet rule constructor.
      Parameters:
      minVersion - the min version, in YYYYMMDD format, or -1 for "as early as possible".
      maxVersion - the maximum packet version this rule supports, in YYYYMMDD format, or -1 for "most recent"
      prefix - The 2-byte code prefix for matching the packet.
      data - The static or dynamic size tag indicator.
      type - The type of the packet, STATIC or DYNAMIC
      name - The name of the packet, currently only for logging.
      clz - The class of the POJO we are serializing and deserializing.
  • Method Details

    • Dynamic

      public static PacketRule Dynamic(short prefix, int sizeTag, Class<?> clz)
      Utility constructor for building a non-packet version specific dynamic packet whose name is derived from the given class.
      Parameters:
      prefix - The 2-byte code prefix for matching the packet.
      sizeTag - The size of the following "packet size" indicator, 2 or 4.
      clz - The class that we are serializing and deserializing.
      Returns:
      The packet rule object.
    • Dynamic

      public static PacketRule Dynamic(int prefix, int sizeTag, Class<?> clz)
    • Static

      public static PacketRule Static(short prefix, int size, Class<?> clz)
      Utility constructor for building a non-packet version specific static packet whose name is derived from the given class.
      Parameters:
      prefix - The 2-byte code prefix for matching the packet.
      size - The size of the following full packet.
      clz - The class that we are serializing and deserializing.
      Returns:
      The packet rule object.
    • Static

      public static PacketRule Static(int prefix, int size, Class<?> clz)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • minVersion

      public int minVersion()
      Returns the value of the minVersion record component.
      Returns:
      the value of the minVersion record component
    • maxVersion

      public int maxVersion()
      Returns the value of the maxVersion record component.
      Returns:
      the value of the maxVersion record component
    • prefix

      public short prefix()
      Returns the value of the prefix record component.
      Returns:
      the value of the prefix record component
    • data

      public int data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • type

      public PacketRule.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • clz

      public Class<?> clz()
      Returns the value of the clz record component.
      Returns:
      the value of the clz record component