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.ByteArrayInputStream
Casper 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 void
readAny(CLValueAny clValue)
Reads all bytes as a genericObject
into aCLValueAny
protected void
readBigInteger(AbstractCLValue<java.math.BigInteger,?> clValue)
Wider numeric values (i.e.void
readBool(CLValueBool clValue)
Boolean values serialize as a single byte; true maps to 1, while false maps to 0.protected byte
readByte()
Reads a single bytevoid
readByteArray(CLValueByteArray clValue, int length)
Reads a byteArrayy into a clvalueprotected byte[]
readBytes(int length)
Reads a specified number of bytesvoid
readI32(CLValueI32 clValue)
Numeric values consisting of 64 bits or less serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.void
readI64(CLValueI64 clValue)
Numeric values consisting of 64 bits or less serialize in the two’s complement representation with little-endian byte order, and the appropriate number of bytes for the bit-width.void
readKey(CLValueKey clValue)
Reads aCLValueKey
value from buffervoid
readPublicKey(CLValuePublicKey clValue)
Reads aCLValuePublicKey
value from buffervoid
readString(CLValueString clValue)
Reads aCLValueString
value from buffervoid
readU128(CLValueU128 clValue)
Reads U128 from buffervoid
readU256(CLValueU256 clValue)
Reads U256 from buffervoid
readU32(CLValueU32 clValue)
Reads aLong
value from buffer, representing an UnsignedInteger
(U32)void
readU512(CLValueU512 clValue)
Reads U512 from buffervoid
readU64(CLValueU64 clValue)
Reads aBigInteger
value from buffer, representing an UnsignedLong
(U32)void
readU8(CLValueU8 clValue)
Numeric values consisting of 64 bits or less 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 InvalidByteStringException
Initializes buffer with decoded bytes from hex-encodedString
- Parameters:
hexString
- hex-encodedString
of 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 less 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 byteArrayy into a clvalue- Parameters:
clValue
- targetCLValueByteArray
length
- the length of the array- Throws:
CLValueDecodeException
- exception holding information of failure to decode aAbstractCLValue
java.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 less 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 aLong
value 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 less 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 aBigInteger
value 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 aCLValueString
value 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 aCLValuePublicKey
value from buffer- Parameters:
clValue
- targetCLValuePublicKey
- Throws:
java.security.NoSuchAlgorithmException
- the requested algorithm was not foundCLValueDecodeException
- exception holding information of failure to decode aAbstractCLValue
java.io.IOException
- error with input/output while reading the byte array
-
readKey
public void readKey(CLValueKey clValue) throws NoSuchKeyTagException, CLValueDecodeException, java.io.IOException
Reads aCLValueKey
value from buffer- Parameters:
clValue
- targetCLValueKey
- Throws:
NoSuchKeyTagException
- the requested key tag was not foundCLValueDecodeException
- exception holding information of failure to decode aAbstractCLValue
java.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 genericObject
into 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.IOException
Reads a single byte- Returns:
- the byte read
- Throws:
CLValueDecodeException
- exception holding information of failure to decode aAbstractCLValue
java.io.IOException
- error with input/output while reading the byte array
-
readBytes
protected byte[] readBytes(int length) throws CLValueDecodeException, java.io.IOException
Reads 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 aAbstractCLValue
java.io.IOException
- error with input/output while reading the byte array
-
-