Search in sources :

Example 1 with Bytes

use of org.bcos.web3j.abi.datatypes.Bytes in project web3sdk by FISCO-BCOS.

the class TypeDecoder method decodeBytes.

static <T extends Bytes> T decodeBytes(String input, int offset, Class<T> type) {
    try {
        String simpleName = type.getSimpleName();
        String[] splitName = simpleName.split(Bytes.class.getSimpleName());
        int length = Integer.parseInt(splitName[1]);
        int hexStringLength = length << 1;
        byte[] bytes = Numeric.hexStringToByteArray(input.substring(offset, offset + hexStringLength));
        return type.getConstructor(byte[].class).newInstance(bytes);
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new UnsupportedOperationException("Unable to create instance of " + type.getName(), e);
    }
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint(org.bcos.web3j.abi.datatypes.Uint) InvocationTargetException(java.lang.reflect.InvocationTargetException) Bytes(org.bcos.web3j.abi.datatypes.Bytes) DynamicBytes(org.bcos.web3j.abi.datatypes.DynamicBytes)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Bytes (org.bcos.web3j.abi.datatypes.Bytes)1 DynamicBytes (org.bcos.web3j.abi.datatypes.DynamicBytes)1 Uint (org.bcos.web3j.abi.datatypes.Uint)1 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)1