Package org.symbol.sdk
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
- CatbufferType
- Shared base for every generated catbuffer struct (PODs and enums do not extend it):
serialize()allocates aWritersized bySerializer.size()and threads it throughserializeInto(Writer).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static final <T extends ByteArray>
TasByteArray(Object value, Class<T> target, Function<byte[], T> ctor) Convert a descriptor value into aByteArraysubtype: 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 rawbyte[]via the supplied constructor reference; an unrelated ByteArray type is rejected.protected static final byte[]protected static final intConverts a descriptor value to an exactintviaConverter.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> Convert a descriptor value to a mutable typed list, validating every element — generatedsetFieldarms use this instead of an unchecked(List<T>)cast so a wrongly-typed element fails here instead of during serialization.protected static final longConverts a descriptor value to alongviaConverter.toLong(Number)/Converter.toLong(String): a fixed-width integral wrapper or a decimal/0x-hex string (BigIntegerand non-integralFloat/Doubleare rejected — pass a u64>= 2^63as a string).Reads a named field.final byte[]Serializes this object to bytes: allocates aWritersized bySerializer.size()and threads it throughserializeInto(Writer).protected abstract voidserializeInto(Writer buffer) Encodes this object's fields into the supplied writer.voidSets a named field.voidsort()Sorts the collections of this object so that it can be serialized canonically.abstract ObjecttoJson()Returns the JSON-serializable projection of this object (nestedMap/Listtree 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 StringSerializestoJson()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, waitMethods 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
Writersized bySerializer.size()and threads it throughserializeInto(Writer).
- Specified by:
serializein interfaceSerializer- Returns:
- Serialized bytes.
-
serializeInto
- 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 toSerializer.size().
-
toJson
- CatbufferType.toJson
- Returns the JSON-serializable projection of this object (nested
Map/Listtree 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
- 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
- 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
- CatbufferType.setField
- Sets a named field. Generated subclasses override with a
switchwhosedefaultarm chains tosuper.setFieldfor inherited fields; the base implementation throws.
- Parameters:
name- Field name (descriptor key).value- Value to assign.
-
getField
- CatbufferType.getField
- Reads a named field. Generated subclasses override with a
switchchaining tosuper.getField(name).
- Parameters:
name- Field name.- Returns:
- Field value (callers cast to the appropriate type).
-
asList
- CatbufferType.asList
- Convert a descriptor value to a mutable typed list, validating every element — generated
setFieldarms 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
nullwhenvalueis null.
-
asBytes
- 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
ByteArraysubtype: 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 rawbyte[]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 forClass.isInstance(java.lang.Object)short-circuit).ctor- Byte-array constructor reference for the target type.- Returns:
- Adapted value (or
nullwhenvalueisnull).
-
asInt
- CatbufferType.asInt
- Converts a descriptor value to an exact
intviaConverter.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
- CatbufferType.asLong
- Converts a descriptor value to a
longviaConverter.toLong(Number)/Converter.toLong(String): a fixed-width integral wrapper or a decimal/0x-hex string (BigIntegerand non-integralFloat/Doubleare rejected — pass a u64>= 2^63as a string).
- Parameters:
value- Source value.- Returns:
- Long value.
-