Search in sources :

Example 1 with DynamicBytes

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

the class TypeDecoder method decodeDynamicBytes.

static DynamicBytes decodeDynamicBytes(String input, int offset) {
    int encodedLength = decodeUintAsInt(input, offset);
    int hexStringEncodedLength = encodedLength << 1;
    int valueOffset = offset + MAX_BYTE_LENGTH_FOR_HEX_STRING;
    String data = input.substring(valueOffset, valueOffset + hexStringEncodedLength);
    byte[] bytes = Numeric.hexStringToByteArray(data);
    return new DynamicBytes(bytes);
}
Also used : DynamicBytes(org.bcos.web3j.abi.datatypes.DynamicBytes) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint(org.bcos.web3j.abi.datatypes.Uint)

Example 2 with DynamicBytes

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

the class TypeDecoder method decodeUtf8String.

static Utf8String decodeUtf8String(String input, int offset) {
    DynamicBytes dynamicBytesResult = decodeDynamicBytes(input, offset);
    byte[] bytes = dynamicBytesResult.getValue();
    return new Utf8String(new String(bytes, StandardCharsets.UTF_8));
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.bcos.web3j.abi.datatypes.DynamicBytes) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String)

Aggregations

DynamicBytes (org.bcos.web3j.abi.datatypes.DynamicBytes)2 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)2 Uint (org.bcos.web3j.abi.datatypes.Uint)1