Class 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
    • Field Summary

      • Fields inherited from class java.io.ByteArrayInputStream

        buf, count, mark, pos
    • Constructor Summary

      Constructors 
      Constructor Description
      CLValueDecoder​(java.lang.String hexString)
      Initializes buffer with decoded bytes from hex-encoded String
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void readAny​(CLValueAny clValue)
      Reads all bytes as a generic Object into a CLValueAny
      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 byte
      void readByteArray​(CLValueByteArray clValue, int length)
      Reads a byteArrayy into a clvalue
      protected byte[] readBytes​(int length)
      Reads a specified number of bytes
      void 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 a CLValueKey value from buffer
      void readPublicKey​(CLValuePublicKey clValue)
      Reads a CLValuePublicKey value from buffer
      void readString​(CLValueString clValue)
      Reads a CLValueString value from buffer
      void readU128​(CLValueU128 clValue)
      Reads U128 from buffer
      void readU256​(CLValueU256 clValue)
      Reads U256 from buffer
      void readU32​(CLValueU32 clValue)
      Reads a Long value from buffer, representing an Unsigned Integer (U32)
      void readU512​(CLValueU512 clValue)
      Reads U512 from buffer
      void readU64​(CLValueU64 clValue)
      Reads a BigInteger value from buffer, representing an Unsigned Long (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.
      • Methods inherited from class java.io.ByteArrayInputStream

        available, close, mark, markSupported, read, read, readAllBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.io.InputStream

        nullInputStream, read, readNBytes
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CLValueDecoder

        public CLValueDecoder​(java.lang.String hexString)
                       throws InvalidByteStringException
        Initializes buffer with decoded bytes from hex-encoded String
        Parameters:
        hexString - hex-encoded String 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 - target CLValueBool
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • 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 - target CLValueU8
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • 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 - target CLValueI32
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • 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 - target CLValueI64
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • readU64

        public void readU64​(CLValueU64 clValue)
                     throws java.io.IOException,
                            CLValueDecodeException
        Reads a BigInteger value from buffer, representing an Unsigned Long (U32)
        Parameters:
        clValue - target CLValueU64
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • 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 - target AbstractCLValue
        Throws:
        java.io.IOException - error with input/output while reading the byte array
        CLValueDecodeException - exception holding information of failure to decode a AbstractCLValue
      • 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 a AbstractCLValue
        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 a AbstractCLValue
        java.io.IOException - error with input/output while reading the byte array