Class CLValueDecoder
- java.lang.Object
-
- java.io.InputStream
-
- java.io.ByteArrayInputStream
-
- com.syntifi.casper.sdk.model.clvalue.encdec.CLValueDecoder
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class CLValueDecoder extends java.io.ByteArrayInputStreamCasper CLValue Decoding methods- Since:
- 0.0.1
- See Also:
AbstractCLValue
-
-
Constructor Summary
Constructors Constructor Description CLValueDecoder(java.lang.String hexString)Initializes buffer with decoded bytes from hex-encodedString
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidreadAny(CLValueAny clValue)Reads all bytes as a genericObjectinto aCLValueAnyprotected voidreadBigInteger(AbstractCLValue<java.math.BigInteger,?> clValue)Wider numeric values (i.e.voidreadBool(CLValueBool clValue)Boolean values serialize as a single byte; true maps to 1, while false maps to 0.protected bytereadByte()Reads a single bytevoidreadByteArray(CLValueByteArray clValue, int length)Reads a byteArray into a clvalueprotected byte[]readBytes(int length)Reads a specified number of bytesvoidreadI32(CLValueI32 clValue)Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.voidreadI64(CLValueI64 clValue)Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.voidreadKey(CLValueKey clValue)Reads aCLValueKeyvalue from buffervoidreadPublicKey(CLValuePublicKey clValue)Reads aCLValuePublicKeyvalue from buffervoidreadString(CLValueString clValue)Reads aCLValueStringvalue from buffervoidreadU128(CLValueU128 clValue)Reads U128 from buffervoidreadU256(CLValueU256 clValue)Reads U256 from buffervoidreadU32(CLValueU32 clValue)Reads aLongvalue from buffer, representing an UnsignedInteger(U32)voidreadU512(CLValueU512 clValue)Reads U512 from buffervoidreadU64(CLValueU64 clValue)Reads aBigIntegervalue from buffer, representing an UnsignedLong(U32)voidreadU8(CLValueU8 clValue)Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.
-
-
-
Constructor Detail
-
CLValueDecoder
public CLValueDecoder(java.lang.String hexString) throws InvalidByteStringExceptionInitializes buffer with decoded bytes from hex-encodedString- Parameters:
hexString- hex-encodedStringof a CLValue- Throws:
InvalidByteStringException- if the byte string is invalid or can't be parsed
-
-
Method Detail
-
readBool
public void readBool(CLValueBool clValue) throws java.io.IOException, CLValueDecodeException
Boolean values serialize as a single byte; true maps to 1, while false maps to 0.- Parameters:
clValue- targetCLValueBool- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU8
public void readU8(CLValueU8 clValue) throws java.io.IOException, CLValueDecodeException
Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.E.g. 7u8 serializes as 0x07
- Parameters:
clValue- targetCLValueU8- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readByteArray
public void readByteArray(CLValueByteArray clValue, int length) throws CLValueDecodeException, java.io.IOException
Reads a byteArray into a clvalue- Parameters:
clValue- targetCLValueByteArraylength- the length of the array- Throws:
CLValueDecodeException- exception holding information of failure to decode aAbstractCLValuejava.io.IOException- error with input/output while reading the byte array
-
readI32
public void readI32(CLValueI32 clValue) throws java.io.IOException, CLValueDecodeException
Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.E.g. 7u32 serializes as 0x07000000 E.g. 1024u32 serializes as 0x00040000
- Parameters:
clValue- targetCLValueI32- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU32
public void readU32(CLValueU32 clValue) throws java.io.IOException, CLValueDecodeException
Reads aLongvalue from buffer, representing an UnsignedInteger(U32)- Parameters:
clValue- targetCLValueU32- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readI64
public void readI64(CLValueI64 clValue) throws java.io.IOException, CLValueDecodeException
Numeric values consisting of 64 bits or fewer serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.E.g. 7u8 serializes as 0x07 E.g. 7u32 serializes as 0x07000000 E.g. 1024u32 serializes as 0x00040000
- Parameters:
clValue- targetCLValueI64- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU64
public void readU64(CLValueU64 clValue) throws java.io.IOException, CLValueDecodeException
Reads aBigIntegervalue from buffer, representing an UnsignedLong(U32)- Parameters:
clValue- targetCLValueU64- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU128
public void readU128(CLValueU128 clValue) throws java.io.IOException, CLValueDecodeException
Reads U128 from buffer- Parameters:
clValue- targetCLValueU128- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU256
public void readU256(CLValueU256 clValue) throws java.io.IOException, CLValueDecodeException
Reads U256 from buffer- Parameters:
clValue- targetCLValueU256- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readU512
public void readU512(CLValueU512 clValue) throws java.io.IOException, CLValueDecodeException
Reads U512 from buffer- Parameters:
clValue- targetCLValueU512- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readBigInteger
protected void readBigInteger(AbstractCLValue<java.math.BigInteger,?> clValue) throws java.io.IOException, CLValueDecodeException
Wider numeric values (i.e. U128, U256, U512) serialize as one byte given the length of the next number (in bytes), followed by the two’s complement representation with little-endian byte order. The number of bytes should be chosen as small as possible to represent the given number. This is done to reduce the serialization size when small numbers are represented within a wide data type.E.g. U512::from(7) serializes as 0x0107 E.g. U512::from(1024) serializes as 0x020004 E.g. U512::from("123456789101112131415") serializes as 0x0957ff1ada959f4eb106
- Parameters:
clValue- targetAbstractCLValue- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readString
public void readString(CLValueString clValue) throws java.io.IOException, CLValueDecodeException
Reads aCLValueStringvalue from buffer- Parameters:
clValue- targetCLValueString- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readPublicKey
public void readPublicKey(CLValuePublicKey clValue) throws java.security.NoSuchAlgorithmException, CLValueDecodeException, java.io.IOException
Reads aCLValuePublicKeyvalue from buffer- Parameters:
clValue- targetCLValuePublicKey- Throws:
java.security.NoSuchAlgorithmException- the requested algorithm was not foundCLValueDecodeException- exception holding information of failure to decode aAbstractCLValuejava.io.IOException- error with input/output while reading the byte array
-
readKey
public void readKey(CLValueKey clValue) throws NoSuchKeyTagException, CLValueDecodeException, java.io.IOException
Reads aCLValueKeyvalue from buffer- Parameters:
clValue- targetCLValueKey- Throws:
NoSuchKeyTagException- the requested key tag was not foundCLValueDecodeException- exception holding information of failure to decode aAbstractCLValuejava.io.IOException- error with input/output while reading the byte array
-
readAny
public void readAny(CLValueAny clValue) throws java.io.IOException, CLValueDecodeException
Reads all bytes as a genericObjectinto aCLValueAny- Parameters:
clValue- targetCLValueAny- Throws:
java.io.IOException- error with input/output while reading the byte arrayCLValueDecodeException- exception holding information of failure to decode aAbstractCLValue
-
readByte
protected byte readByte() throws CLValueDecodeException, java.io.IOExceptionReads a single byte- Returns:
- the byte read
- Throws:
CLValueDecodeException- exception holding information of failure to decode aAbstractCLValuejava.io.IOException- error with input/output while reading the byte array
-
readBytes
protected byte[] readBytes(int length) throws CLValueDecodeException, java.io.IOExceptionReads a specified number of bytes- Parameters:
length- the number of bytes to read- Returns:
- bytes read
- Throws:
CLValueDecodeException- exception holding information of failure to decode aAbstractCLValuejava.io.IOException- error with input/output while reading the byte array
-
-