Package anbxj

Class AnBx_CustomType

java.lang.Object
anbxj.AnBx_CustomType
All Implemented Interfaces:
Serializable

public abstract class AnBx_CustomType extends Object implements Serializable
Base class for user-defined types generated by the AnBx compiler.

Each custom type declared in an AnBx protocol specification is compiled to a Java class that extends AnBx_CustomType. The generated class wraps a Crypto_ByteArray that holds the concrete value of the custom type.

Subclasses must provide:

This class provides value-based equals and hashCode semantics, and supports deterministic byte serialisation via toByteArray().

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Crypto_ByteArray
    The wrapped byte array value.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AnBx_CustomType(byte[] bytes)
    Constructs a new instance from the given constant byte array.
    protected
    AnBx_CustomType(int length)
    Constructs a new instance with a freshly generated random value of the specified length.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Compares this object with the specified object for equality.
    Returns the wrapped byte array value.
    final int
    Returns the hash code of this instance.
    byte[]
    Returns the raw bytes of this custom type instance.

    Methods inherited from class java.lang.Object

    clone, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AnBx_CustomType

      protected AnBx_CustomType(int length)
      Constructs a new instance with a freshly generated random value of the specified length.
      Parameters:
      length - the length in bytes of the value to generate
      Throws:
      IllegalArgumentException - if length <= 0
    • AnBx_CustomType

      protected AnBx_CustomType(byte[] bytes)
      Constructs a new instance from the given constant byte array.
      Parameters:
      bytes - the constant byte array value (must not be null)
      Throws:
      NullPointerException - if bytes is null
  • Method Details

    • getValue

      public Crypto_ByteArray getValue()
      Returns the wrapped byte array value.
      Returns:
      the wrapped value (never null)
    • toByteArray

      public byte[] toByteArray()
      Returns the raw bytes of this custom type instance.

      The returned array is a fresh copy; modifications to it will not affect the internal state of this object.

      Returns:
      a fresh copy of the underlying byte array (never null)
    • equals

      public final boolean equals(Object obj)
      Compares this object with the specified object for equality.

      Two instances are equal if they have the same class and their wrapped byte arrays contain identical bytes.

      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with
      Returns:
      true if the objects are equal; false otherwise
    • hashCode

      public final int hashCode()
      Returns the hash code of this instance.

      The hash code is computed from both the class and the wrapped value.

      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this instance