Package anbxj
Class AnBx_CustomType
java.lang.Object
anbxj.AnBx_CustomType
- All Implemented Interfaces:
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:
- A public parameterless constructor that invokes
AnBx_CustomType(int)with a fixed length. - A public constructor that accepts a
byte[]and invokesAnBx_CustomType(byte[])for constant values.
This class provides value-based equals and hashCode
semantics, and supports deterministic byte serialisation via
toByteArray().
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAnBx_CustomType(byte[] bytes) Constructs a new instance from the given constant byte array.protectedAnBx_CustomType(int length) Constructs a new instance with a freshly generated random value of the specified length. -
Method Summary
-
Field Details
-
value
The wrapped byte array value.
-
-
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- iflength <= 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 benull)- Throws:
NullPointerException- ifbytesisnull
-
-
Method Details
-
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
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.
-
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.
-