@Test public void testDynamicArray() { assertThat(TypeDecoder.decodeDynamicArray( "0000000000000000000000000000000000000000000000000000000000000000", 0, new TypeReference<DynamicArray<Uint256>>() { } ), equalTo(DynamicArray.empty("uint256"))); assertThat(TypeDecoder.decodeDynamicArray( "0000000000000000000000000000000000000000000000000000000000000002" + "000000000000000000000000000000000000000000000000000000000000000a" + "0000000000000000000000000000000000000000000000007fffffffffffffff", 0, new TypeReference<DynamicArray<Uint256>>() { } ), equalTo(new DynamicArray<Uint256>( new Uint256(BigInteger.TEN), new Uint256(BigInteger.valueOf(Long.MAX_VALUE))))); assertThat(TypeDecoder.decodeDynamicArray( "0000000000000000000000000000000000000000000000000000000000000002" + "000000000000000000000000000000000000000000000000000000000000000d" + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000" + "000000000000000000000000000000000000000000000000000000000000000d" + "776f726c64212048656c6c6f2c00000000000000000000000000000000000000", 0, new TypeReference<DynamicArray<Utf8String>>() { } ), equalTo(new DynamicArray<Utf8String>( new Utf8String("Hello, world!"), new Utf8String("world! Hello,")))); }
@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); }
TypeDecoder { @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); } }
TypeDecoder { @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); }  }
TypeDecoder { @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); }  static T decode(
            String input, int offset, TypeReference<T> typeReference); }
TypeDecoder { @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); }  static T decode(
            String input, int offset, TypeReference<T> typeReference);  }