use of org.bcos.web3j.abi.datatypes.Int in project web3sdk by FISCO-BCOS.
the class AbiTypesMapperGenerator method generateIntTypes.
private MethodSpec.Builder generateIntTypes(MethodSpec.Builder builder, String packageName) {
for (int bitSize = 8; bitSize <= Type.MAX_BIT_LENGTH; bitSize += 8) {
builder = addStatement(builder, packageName, Uint.TYPE_NAME + bitSize, Uint.class.getSimpleName() + bitSize);
builder = addStatement(builder, packageName, Int.TYPE_NAME + bitSize, Int.class.getSimpleName() + bitSize);
}
return builder;
}
use of org.bcos.web3j.abi.datatypes.Int in project web3sdk by FISCO-BCOS.
the class TypeDecoder method decodeNumeric.
static <T extends NumericType> T decodeNumeric(String input, Class<T> type) {
try {
byte[] inputByteArray = Numeric.hexStringToByteArray(input);
int typeLengthAsBytes = getTypeLengthInBytes(type);
byte[] resultByteArray = new byte[typeLengthAsBytes + 1];
if (Int.class.isAssignableFrom(type) || Fixed.class.isAssignableFrom(type)) {
// take MSB as sign bit
resultByteArray[0] = inputByteArray[0];
}
int valueOffset = Type.MAX_BYTE_LENGTH - typeLengthAsBytes;
System.arraycopy(inputByteArray, valueOffset, resultByteArray, 1, typeLengthAsBytes);
BigInteger numericValue = new BigInteger(resultByteArray);
return type.getConstructor(BigInteger.class).newInstance(numericValue);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new UnsupportedOperationException("Unable to create instance of " + type.getName(), e);
}
}
use of org.bcos.web3j.abi.datatypes.Int in project web3sdk by FISCO-BCOS.
the class TypeDecoder method decodeDynamicArray.
@SuppressWarnings("unchecked")
static <T extends Type> T decodeDynamicArray(String input, int offset, TypeReference<T> typeReference) {
int length = decodeUintAsInt(input, offset);
BiFunction<List<T>, String, T> function = (elements, typeName) -> {
if (elements.isEmpty()) {
return (T) DynamicArray.empty(typeName);
} else {
return (T) new DynamicArray<>(elements);
}
};
int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;
return decodeArrayElements(input, valueOffset, typeReference, length, function);
}
Aggregations