@Test void shouldParseFullObjects() { Bytes bytes = fromHexString("0x03000000426F62046807B7711F010000000000000000000000000000000000000000000000000000"); SomeObject readObject = SSZ.decode(bytes, r -> new SomeObject(r.readString(), r.readInt8(), r.readBigInteger(256))); assertEquals("Bob", readObject.name); assertEquals(4, readObject.number); assertEquals(BigInteger.valueOf(1234563434344L), readObject.longNumber); }
@Override public BigInteger readBigInteger(int bitLength) { checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8"); int byteLength = bitLength / 8; ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer"); return consumeBytes(byteLength).toBigInteger(LITTLE_ENDIAN); }
BytesSSZReader implements SSZReader { @Override public BigInteger readBigInteger(int bitLength) { checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8"); int byteLength = bitLength / 8; ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer"); return consumeBytes(byteLength).toBigInteger(LITTLE_ENDIAN); } }
BytesSSZReader implements SSZReader { @Override public BigInteger readBigInteger(int bitLength) { checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8"); int byteLength = bitLength / 8; ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer"); return consumeBytes(byteLength).toBigInteger(LITTLE_ENDIAN); } BytesSSZReader(Bytes content); }
BytesSSZReader implements SSZReader { @Override public BigInteger readBigInteger(int bitLength) { checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8"); int byteLength = bitLength / 8; ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer"); return consumeBytes(byteLength).toBigInteger(LITTLE_ENDIAN); } BytesSSZReader(Bytes content); @Override Bytes readBytes(int limit); @Override int readInt(int bitLength); @Override long readLong(int bitLength); @Override BigInteger readBigInteger(int bitLength); @Override BigInteger readUnsignedBigInteger(int bitLength); @Override UInt256 readUInt256(); @Override UInt384 readUInt384(); @Override Bytes readAddress(); @Override Bytes readHash(int hashLength); @Override List<Bytes> readBytesList(int limit); @Override List<String> readStringList(int limit); @Override List<Integer> readIntList(int bitLength); @Override List<Long> readLongIntList(int bitLength); @Override List<BigInteger> readBigIntegerList(int bitLength); @Override List<BigInteger> readUnsignedBigIntegerList(int bitLength); @Override List<UInt256> readUInt256List(); @Override List<UInt384> readUInt384List(); @Override List<Bytes> readAddressList(); @Override List<Bytes> readHashList(int hashLength); @Override List<Boolean> readBooleanList(); @Override boolean isComplete(); }
BytesSSZReader implements SSZReader { @Override public BigInteger readBigInteger(int bitLength) { checkArgument(bitLength % 8 == 0, "bitLength must be a multiple of 8"); int byteLength = bitLength / 8; ensureBytes(byteLength, () -> "SSZ encoded data has insufficient length to read a " + bitLength + "-bit integer"); return consumeBytes(byteLength).toBigInteger(LITTLE_ENDIAN); } BytesSSZReader(Bytes content); @Override Bytes readBytes(int limit); @Override int readInt(int bitLength); @Override long readLong(int bitLength); @Override BigInteger readBigInteger(int bitLength); @Override BigInteger readUnsignedBigInteger(int bitLength); @Override UInt256 readUInt256(); @Override UInt384 readUInt384(); @Override Bytes readAddress(); @Override Bytes readHash(int hashLength); @Override List<Bytes> readBytesList(int limit); @Override List<String> readStringList(int limit); @Override List<Integer> readIntList(int bitLength); @Override List<Long> readLongIntList(int bitLength); @Override List<BigInteger> readBigIntegerList(int bitLength); @Override List<BigInteger> readUnsignedBigIntegerList(int bitLength); @Override List<UInt256> readUInt256List(); @Override List<UInt384> readUInt384List(); @Override List<Bytes> readAddressList(); @Override List<Bytes> readHashList(int hashLength); @Override List<Boolean> readBooleanList(); @Override boolean isComplete();  }