Package org.polkadot.types.codec
Class Option<T extends Codec>
- java.lang.Object
-
- org.polkadot.types.codec.Base<T>
-
- org.polkadot.types.codec.Option<T>
-
- All Implemented Interfaces:
Codec
- Direct Known Subclasses:
PrefabWasmModule.PrefabWasmModuleReserved
public class Option<T extends Codec> extends Base<T> implements Codec
An Option is an optional field. Basically the first byte indicates that there is is value to follow. If the byte is `1` there is an actual value. So the Option implements that - decodes, checks for optionality and wraps the required structure with a value if/as required/found.
-
-
Constructor Summary
Constructors Constructor Description Option(Types.ConstructorCodec type, java.lang.Object value)
-
Method Summary
Modifier and Type Method Description booleaneq(java.lang.Object other)Compares the value of the input to see if there is a matchintgetEncodedLength()The length of the value when encoded as a Uint8ArrayCodecgetValue()The actual value for the OptionbooleanisEmpty()Checks if the Option has no valuebooleanisNone()Checks if the Option has no valuebooleanisSome()Checks if the Option has a valuejava.lang.StringtoHex()Returns a hex string representation of the valuejava.lang.ObjecttoJson()Converts the Object to JSON, typically used for RPC transfersjava.lang.StringtoString()Returns the string representation of the valuebyte[]toU8a(boolean isBare)Encodes the value as a Uint8Array as per the parity-codec specificationsTunwrap()Returns the value that the Option represents (if available), throws if null<O> java.lang.ObjectunwrapOr(O defaultValue)static <O> Types.ConstructorCodec<Option>with(Types.ConstructorCodec type)
-
-
-
Constructor Detail
-
Option
public Option(Types.ConstructorCodec type, java.lang.Object value)
-
-
Method Detail
-
with
public static <O> Types.ConstructorCodec<Option> with(Types.ConstructorCodec type)
-
getEncodedLength
public int getEncodedLength()
The length of the value when encoded as a Uint8Array- Specified by:
getEncodedLengthin interfaceCodec
-
isNone
public boolean isNone()
Checks if the Option has no value
-
isSome
public boolean isSome()
Checks if the Option has a value
-
isEmpty
public boolean isEmpty()
Checks if the Option has no value
-
eq
public boolean eq(java.lang.Object other)
Compares the value of the input to see if there is a match
-
toHex
public java.lang.String toHex()
Returns a hex string representation of the value
-
toJson
public java.lang.Object toJson()
Converts the Object to JSON, typically used for RPC transfers
-
toString
public java.lang.String toString()
Returns the string representation of the value- Overrides:
toStringin classjava.lang.Object
-
toU8a
public byte[] toU8a(boolean isBare)
Encodes the value as a Uint8Array as per the parity-codec specifications
-
unwrap
public T unwrap()
Returns the value that the Option represents (if available), throws if null
-
unwrapOr
public <O> java.lang.Object unwrapOr(O defaultValue)
- Parameters:
defaultValue- The value to return if the option isNone Returns the value that the Option represents (if available) or defaultValue if none
-
getValue
public Codec getValue()
The actual value for the Option
-
-