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);
}
}
Aggregations