@Test public void testUintDecode() { assertThat(TypeDecoder.decodeNumeric( "0000000000000000000000000000000000000000000000000000000000000000", Uint64.class ), is(new Uint64(BigInteger.ZERO))); assertThat(TypeDecoder.decodeNumeric( "0000000000000000000000000000000000000000000000007fffffffffffffff", Uint64.class ), is(new Uint64(BigInteger.valueOf(Long.MAX_VALUE)))); assertThat(TypeDecoder.decodeNumeric( "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", Uint64.class ), is(new Uint64(new BigInteger( "0ffffffffffffffff", 16)))); }
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)) { 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); } }
TypeDecoder { 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)) { 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); } } }
TypeDecoder { 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)) { 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); } }  }
TypeDecoder { 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)) { 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); } }  static T decode(
            String input, int offset, TypeReference<T> typeReference); }
TypeDecoder { 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)) { 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); } }  static T decode(
            String input, int offset, TypeReference<T> typeReference);  }