Package com.algorand.algosdk.abi
Class ABIType
- java.lang.Object
-
- com.algorand.algosdk.abi.ABIType
-
- Direct Known Subclasses:
TypeAddress
,TypeArrayDynamic
,TypeArrayStatic
,TypeBool
,TypeByte
,TypeString
,TypeTuple
,TypeUfixed
,TypeUint
public abstract class ABIType extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
ABI_DYNAMIC_HEAD_BYTE_LEN
-
Constructor Summary
Constructors Constructor Description ABIType()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
byteLen()
Precompute the byte size of the static ABI typed valueprotected static TypeTuple
castToTupleType(int size, ABIType t)
Cast a dynamic/static array to ABI tuple typeabstract Object
decode(byte[] encoded)
Decode ABI encoded byte array to JAVA values from ABI type schemesabstract byte[]
encode(Object obj)
Encode JAVA values with ABI rules based on the ABI type schemesabstract boolean
equals(Object obj)
protected static int
findBoolLR(ABIType[] typeArray, int index, int delta)
protected static byte[]
getContentEncoded(byte[] encoded)
Take the bytes after the first 2 bytes in the byte array (consider the byte array to be an encoding for ABI dynamic typed value)protected static byte[]
getLengthEncoded(byte[] encoded)
Take the first 2 bytes in the byte array (consider the byte array to be an encoding for ABI dynamic typed value)abstract boolean
isDynamic()
Check if this ABI type is a dynamic type.static List<String>
parseTupleContent(String str)
static ABIType
valueOf(String str)
Deserialize ABI type scheme from string
-
-
-
Field Detail
-
ABI_DYNAMIC_HEAD_BYTE_LEN
public static final int ABI_DYNAMIC_HEAD_BYTE_LEN
- See Also:
- Constant Field Values
-
-
Method Detail
-
isDynamic
public abstract boolean isDynamic()
Check if this ABI type is a dynamic type.- Returns:
- boolean decision if the ABI type is dynamic.
-
byteLen
public abstract int byteLen()
Precompute the byte size of the static ABI typed value- Returns:
- the byte size of the ABI value
- Throws:
IllegalArgumentException
- if the ABI type is dynamic typed
-
encode
public abstract byte[] encode(Object obj)
Encode JAVA values with ABI rules based on the ABI type schemes- Parameters:
obj
- JAVA values- Returns:
- byte[] of ABI encoding
- Throws:
IllegalArgumentException
- if encoder cannot infer the type from obj
-
decode
public abstract Object decode(byte[] encoded)
Decode ABI encoded byte array to JAVA values from ABI type schemes- Parameters:
encoded
- byte array of ABI encoding- Returns:
- JAVA object of corresponding values
- Throws:
IllegalArgumentException
- if encoded byte array cannot match with ABI encoding rules
-
valueOf
public static ABIType valueOf(String str)
Deserialize ABI type scheme from string- Parameters:
str
- string representation of ABI type schemes- Returns:
- ABI type scheme object
- Throws:
IllegalArgumentException
- if ABI type serialization strings are corrupted
-
findBoolLR
protected static int findBoolLR(ABIType[] typeArray, int index, int delta)
-
getLengthEncoded
protected static byte[] getLengthEncoded(byte[] encoded)
Take the first 2 bytes in the byte array (consider the byte array to be an encoding for ABI dynamic typed value)- Parameters:
encoded
- an ABI encoding byte array- Returns:
- the first 2 bytes of the ABI encoding byte array
- Throws:
IllegalArgumentException
- if the encoded byte array has length < 2
-
getContentEncoded
protected static byte[] getContentEncoded(byte[] encoded)
Take the bytes after the first 2 bytes in the byte array (consider the byte array to be an encoding for ABI dynamic typed value)- Parameters:
encoded
- an ABI encoding byte array- Returns:
- the tailing bytes after the first 2 bytes of the ABI encoding byte array
- Throws:
IllegalArgumentException
- if the encoded byte array has length < 2
-
-