Class ABIType

    • Field Detail

      • ABI_DYNAMIC_HEAD_BYTE_LEN

        public static final int ABI_DYNAMIC_HEAD_BYTE_LEN
        See Also:
        Constant Field Values
    • Constructor Detail

      • ABIType

        public ABIType()
    • 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.
      • equals

        public abstract boolean equals​(Object obj)
        Overrides:
        equals in class Object
      • 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
      • parseTupleContent

        public static List<String> parseTupleContent​(String str)
      • 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
      • castToTupleType

        protected static TypeTuple castToTupleType​(int size,
                                                   ABIType t)
        Cast a dynamic/static array to ABI tuple type
        Parameters:
        size - length of the ABI array
        t - ABI type of the element of the ABI array
        Returns:
        a type-cast from ABI array to an ABI tuple type