Class CatbufferType

java.lang.Object
org.symbol.sdk.CatbufferType
All Implemented Interfaces:
Serializer
Direct Known Subclasses:
AddressResolutionEntry, AddressResolutionStatement, Block, BlockStatement, Cosignature, DetachedCosignature, EmbeddedTransaction, FinalizationRound, FinalizedBlockHeader, Mosaic, MosaicResolutionEntry, MosaicResolutionStatement, Receipt, ReceiptSource, Transaction, TransactionStatement, UnresolvedMosaic, VrfProof

public abstract class CatbufferType extends Object implements Serializer
CatbufferType
Shared base for every generated catbuffer struct (PODs and enums do not extend it): serialize() allocates a Writer sized by Serializer.size() and threads it through serializeInto(Writer).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static final <T extends ByteArray>
    T
    asByteArray(Object value, Class<T> target, Function<byte[],T> ctor)
    Convert a descriptor value into a ByteArray subtype: short-circuits when the value already matches the target type, otherwise rewraps the underlying bytes of a same-named ByteArray twin (across packages) or a raw byte[] via the supplied constructor reference; an unrelated ByteArray type is rejected.
    protected static final byte[]
    asBytes(Object value)
    Convert a descriptor value to byte[]: accepts byte[] as-is, UTF-8-encodes Strings, unwraps any ByteArray, and passes null through.
    protected static final int
    asInt(Object value)
    Converts a descriptor value to an exact int via Converter.toInt(Number) / Converter.toInt(String): a fixed-width integral wrapper or a decimal/0x-hex string, rejecting out-of-range values rather than truncating.
    protected static final <T> List<T>
    asList(Object value, Class<T> elementType)
    Convert a descriptor value to a mutable typed list, validating every element — generated setField arms use this instead of an unchecked (List<T>) cast so a wrongly-typed element fails here instead of during serialization.
    protected static final long
    asLong(Object value)
    Converts a descriptor value to a long via Converter.toLong(Number) / Converter.toLong(String): a fixed-width integral wrapper or a decimal/0x-hex string (BigInteger and non-integral Float/Double are rejected — pass a u64 >= 2^63 as a string).
    Reads a named field.
    final byte[]
    Serializes this object to bytes: allocates a Writer sized by Serializer.size() and threads it through serializeInto(Writer).
    protected abstract void
    Encodes this object's fields into the supplied writer.
    void
    setField(String name, Object value)
    Sets a named field.
    void
    Sorts the collections of this object so that it can be serialized canonically.
    abstract Object
    Returns the JSON-serializable projection of this object (nested Map/List tree with string-encoded u64 values); the projection is a wire snapshot, not a descriptor — byte fields render as hex while descriptor input reads strings as UTF-8 text.
    final String
    Serializes toJson() to a JSON document.
    Returns the type-hint map used by the descriptor pipeline to pick a rule per key; default is an empty map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.symbol.sdk.Serializer

    size
  • Constructor Details

    • CatbufferType

      public CatbufferType()
  • Method Details

    • serialize

      public final byte[] serialize()
      CatbufferType.serialize
      Serializes this object to bytes: allocates a Writer sized by Serializer.size() and threads it through serializeInto(Writer).
      Specified by:
      serialize in interface Serializer
      Returns:
      Serialized bytes.
    • serializeInto

      protected abstract void serializeInto(Writer buffer)
      CatbufferType.serializeInto
      Encodes this object's fields into the supplied writer. Subclasses extending an abstract struct must call super.serializeInto(buffer) before writing their own fields so parent-defined headers land in canonical order.
      Parameters:
      buffer - Output writer pre-sized to Serializer.size().
    • toJson

      public abstract Object toJson()
      CatbufferType.toJson
      Returns the JSON-serializable projection of this object (nested Map/List tree with string-encoded u64 values); the projection is a wire snapshot, not a descriptor — byte fields render as hex while descriptor input reads strings as UTF-8 text.
      Returns:
      JSON-serializable representation of this object.
    • toJsonString

      public final String toJsonString()
      CatbufferType.toJsonString
      Serializes toJson() to a JSON document.
      Returns:
      JSON document string.
    • sort

      public void sort()
      CatbufferType.sort
      Sorts the collections of this object so that it can be serialized canonically. Default is a no-op; structs with sort-key typed-array fields override.
    • typeHints

      public Map<String,String> typeHints()
      CatbufferType.typeHints
      Returns the type-hint map used by the descriptor pipeline to pick a rule per key; default is an empty map.
      Returns:
      Field-name → rule-key map.
    • setField

      public void setField(String name, Object value)
      CatbufferType.setField
      Sets a named field. Generated subclasses override with a switch whose default arm chains to super.setField for inherited fields; the base implementation throws.
      Parameters:
      name - Field name (descriptor key).
      value - Value to assign.
    • getField

      public Object getField(String name)
      CatbufferType.getField
      Reads a named field. Generated subclasses override with a switch chaining to super.getField(name).
      Parameters:
      name - Field name.
      Returns:
      Field value (callers cast to the appropriate type).
    • asList

      protected static final <T> List<T> asList(Object value, Class<T> elementType)
      CatbufferType.asList
      Convert a descriptor value to a mutable typed list, validating every element — generated setField arms use this instead of an unchecked (List<T>) cast so a wrongly-typed element fails here instead of during serialization.
      Type Parameters:
      T - Element type.
      Parameters:
      value - Raw descriptor value.
      elementType - Expected element class.
      Returns:
      Mutable list of checked elements, or null when value is null.
    • asBytes

      protected static final byte[] asBytes(Object value)
      CatbufferType.asBytes
      Convert a descriptor value to byte[]: accepts byte[] as-is, UTF-8-encodes Strings, unwraps any ByteArray, and passes null through.
      Parameters:
      value - Source value.
      Returns:
      Byte array view of the value.
    • asByteArray

      protected static final <T extends ByteArray> T asByteArray(Object value, Class<T> target, Function<byte[],T> ctor)
      CatbufferType.asByteArray
      Convert a descriptor value into a ByteArray subtype: short-circuits when the value already matches the target type, otherwise rewraps the underlying bytes of a same-named ByteArray twin (across packages) or a raw byte[] via the supplied constructor reference; an unrelated ByteArray type is rejected.
      Type Parameters:
      T - Target type.
      Parameters:
      value - Source value.
      target - Target class (also used for Class.isInstance(java.lang.Object) short-circuit).
      ctor - Byte-array constructor reference for the target type.
      Returns:
      Adapted value (or null when value is null).
    • asInt

      protected static final int asInt(Object value)
      CatbufferType.asInt
      Converts a descriptor value to an exact int via Converter.toInt(Number) / Converter.toInt(String): a fixed-width integral wrapper or a decimal/0x-hex string, rejecting out-of-range values rather than truncating.
      Parameters:
      value - Source value.
      Returns:
      Integer value.
    • asLong

      protected static final long asLong(Object value)
      CatbufferType.asLong
      Converts a descriptor value to a long via Converter.toLong(Number) / Converter.toLong(String): a fixed-width integral wrapper or a decimal/0x-hex string (BigInteger and non-integral Float/Double are rejected — pass a u64 >= 2^63 as a string).
      Parameters:
      value - Source value.
      Returns:
      Long value.