Class ABIStreamingEncoder


  • public final class ABIStreamingEncoder
    extends java.lang.Object
    Utility class for AVM ABI encoding.

    Instances of this class are stateful, allowing several pieces of data to be serialized into the same buffer.

    • Constructor Detail

      • ABIStreamingEncoder

        public ABIStreamingEncoder()
        Creates a new encoder, and sets the buffer size to 64 KiB.
      • ABIStreamingEncoder

        public ABIStreamingEncoder​(byte[] array)
        Creates a new encoder, which writes into the provided array. This array must be the expected size of the final encoding.
        Parameters:
        array - the array into which encoded bytes will be written.
    • Method Detail

      • toBytes

        public byte[] toBytes()
        Creates and returns a byte array representing everything that has been encoded so far. Resets the buffer and its underlying array to an empty state.
        Returns:
        The byte array representing everything encoded so far.
      • encodeOneByte

        public ABIStreamingEncoder encodeOneByte​(byte data)
        Encode one byte.
        Parameters:
        data - one byte
        Returns:
        the encoder with this element written into its buffer
      • encodeOneBoolean

        public ABIStreamingEncoder encodeOneBoolean​(boolean data)
        Encode one boolean.
        Parameters:
        data - one boolean
        Returns:
        the encoder with this element written into its buffer
      • encodeOneCharacter

        public ABIStreamingEncoder encodeOneCharacter​(char data)
        Encode one char.
        Parameters:
        data - one char
        Returns:
        the encoder with this element written into its buffer
      • encodeOneShort

        public ABIStreamingEncoder encodeOneShort​(short data)
        Encode one short.
        Parameters:
        data - one short
        Returns:
        the encoder with this element written into its buffer
      • encodeOneInteger

        public ABIStreamingEncoder encodeOneInteger​(int data)
        Encode one int.
        Parameters:
        data - one int
        Returns:
        the encoder with this element written into its buffer
      • encodeOneLong

        public ABIStreamingEncoder encodeOneLong​(long data)
        Encode one long.
        Parameters:
        data - one long
        Returns:
        the encoder with this element written into its buffer
      • encodeOneFloat

        public ABIStreamingEncoder encodeOneFloat​(float data)
        Encode one float.
        Parameters:
        data - one float
        Returns:
        the encoder with this element written into its buffer
      • encodeOneDouble

        public ABIStreamingEncoder encodeOneDouble​(double data)
        Encode one double.
        Parameters:
        data - one double
        Returns:
        the encoder with this element written into its buffer
      • encodeOneByteArray

        public ABIStreamingEncoder encodeOneByteArray​(byte[] data)
        Encode one byte array.
        Parameters:
        data - one byte array
        Returns:
        the encoder with this element written into its buffer
      • getLengthOfOneByteArray

        public static int getLengthOfOneByteArray​(byte[] data)
        Returns the length of the ABI encoding of this byte array.
        Parameters:
        data - one byte array
        Returns:
        the length of the ABI encoding of this byte array.
      • encodeOneBooleanArray

        public ABIStreamingEncoder encodeOneBooleanArray​(boolean[] data)
        Encode one boolean array.
        Parameters:
        data - one boolean array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_BOOLEAN
      • getLengthOfOneBooleanArray

        public static int getLengthOfOneBooleanArray​(boolean[] data)
        Returns the length of the ABI encoding of this boolean array.
        Parameters:
        data - one boolean array
        Returns:
        the length of the ABI encoding of this boolean array.
      • encodeOneCharacterArray

        public ABIStreamingEncoder encodeOneCharacterArray​(char[] data)
        Encode one char array.
        Parameters:
        data - one character array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_CHAR
      • getLengthOfOneCharacterArray

        public static int getLengthOfOneCharacterArray​(char[] data)
        Returns the length of the ABI encoding of this character array.
        Parameters:
        data - one character array
        Returns:
        the length of the ABI encoding of this character array.
      • encodeOneShortArray

        public ABIStreamingEncoder encodeOneShortArray​(short[] data)
        Encode one short array.
        Parameters:
        data - one short array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_SHORT
      • getLengthOfOneShortArray

        public static int getLengthOfOneShortArray​(short[] data)
        Returns the length of the ABI encoding of this short array.
        Parameters:
        data - one short array
        Returns:
        the length of the ABI encoding of this short array.
      • encodeOneIntegerArray

        public ABIStreamingEncoder encodeOneIntegerArray​(int[] data)
        Encode one int array.
        Parameters:
        data - one integer array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_INT
      • getLengthOfOneIntegerArray

        public static int getLengthOfOneIntegerArray​(int[] data)
        Returns the length of the ABI encoding of this integer array.
        Parameters:
        data - one integer array
        Returns:
        the length of the ABI encoding of this integer array.
      • encodeOneLongArray

        public ABIStreamingEncoder encodeOneLongArray​(long[] data)
        Encode one long array.
        Parameters:
        data - one long array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_LONG
      • getLengthOfOneLongArray

        public static int getLengthOfOneLongArray​(long[] data)
        Returns the length of the ABI encoding of this long array.
        Parameters:
        data - one long array
        Returns:
        the length of the ABI encoding of this long array.
      • encodeOneFloatArray

        public ABIStreamingEncoder encodeOneFloatArray​(float[] data)
        Encode one float array.
        Parameters:
        data - one float array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_FLOAT
      • getLengthOfOneFloatArray

        public static int getLengthOfOneFloatArray​(float[] data)
        Returns the length of the ABI encoding of this float array.
        Parameters:
        data - one float array
        Returns:
        the length of the ABI encoding of this float array.
      • encodeOneDoubleArray

        public ABIStreamingEncoder encodeOneDoubleArray​(double[] data)
        Encode one double array.
        Parameters:
        data - one double array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by A_DOUBLE
      • getLengthOfOneDoubleArray

        public static int getLengthOfOneDoubleArray​(double[] data)
        Returns the length of the ABI encoding of this double array.
        Parameters:
        data - one double array
        Returns:
        the length of the ABI encoding of this double array.
      • encodeOneString

        public ABIStreamingEncoder encodeOneString​(java.lang.String data)
        Encode one string.
        Parameters:
        data - one string
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by STRING
      • getLengthOfOneString

        public static int getLengthOfOneString​(java.lang.String data)
        Returns the length of the ABI encoding of this String.
        Parameters:
        data - one String
        Returns:
        the length of the ABI encoding of this String.
      • encodeOneAddress

        public ABIStreamingEncoder encodeOneAddress​(Address data)
        Encode one address.
        Parameters:
        data - one address
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by ADDRESS
      • encodeOneBigInteger

        public ABIStreamingEncoder encodeOneBigInteger​(java.math.BigInteger data)
        Encode one BigInteger.
        Parameters:
        data - one BigInteger
        Returns:
        the encoder with this element written into its buffer Null is encoded as the two identifiers: NULL, followed by BIGINT
      • getLengthOfOneAddress

        public static int getLengthOfOneAddress​(Address data)
        Returns the length of the ABI encoding of this Address.
        Parameters:
        data - one Address
        Returns:
        the length of the ABI encoding of this Address.
      • encodeOne2DByteArray

        public ABIStreamingEncoder encodeOne2DByteArray​(byte[][] data)
        Encode one 2D byte array.
        Parameters:
        data - one 2D byte array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_BYTE
      • getLengthOfOne2DByteArray

        public static int getLengthOfOne2DByteArray​(byte[][] data)
        Returns the length of the ABI encoding of this 2D byte array.
        Parameters:
        data - one 2D byte array
        Returns:
        the length of the ABI encoding of this 2D byte array.
      • encodeOne2DBooleanArray

        public ABIStreamingEncoder encodeOne2DBooleanArray​(boolean[][] data)
        Encode one 2D boolean array.
        Parameters:
        data - one 2D boolean array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_BOOLEAN
      • getLengthOfOne2DBooleanArray

        public static int getLengthOfOne2DBooleanArray​(boolean[][] data)
        Returns the length of the ABI encoding of this 2D boolean array.
        Parameters:
        data - one 2D boolean array
        Returns:
        the length of the ABI encoding of this 2D boolean array.
      • encodeOne2DCharacterArray

        public ABIStreamingEncoder encodeOne2DCharacterArray​(char[][] data)
        Encode one 2D character array.
        Parameters:
        data - one 2D character array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_CHAR
      • getLengthOfOne2DCharacterArray

        public static int getLengthOfOne2DCharacterArray​(char[][] data)
        Returns the length of the ABI encoding of this 2D character array.
        Parameters:
        data - one 2D character array
        Returns:
        the length of the ABI encoding of this 2D character array.
      • encodeOne2DShortArray

        public ABIStreamingEncoder encodeOne2DShortArray​(short[][] data)
        Encode one 2D short array.
        Parameters:
        data - one 2D short array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_SHORT
      • getLengthOfOne2DShortArray

        public static int getLengthOfOne2DShortArray​(short[][] data)
        Returns the length of the ABI encoding of this 2D short array.
        Parameters:
        data - one 2D short array
        Returns:
        the length of the ABI encoding of this 2D short array.
      • encodeOne2DIntegerArray

        public ABIStreamingEncoder encodeOne2DIntegerArray​(int[][] data)
        Encode one 2D integer array.
        Parameters:
        data - one 2D integer array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_INT
      • getLengthOfOne2DIntegerArray

        public static int getLengthOfOne2DIntegerArray​(int[][] data)
        Returns the length of the ABI encoding of this 2D integer array.
        Parameters:
        data - one 2D integer array
        Returns:
        the length of the ABI encoding of this 2D integer array.
      • encodeOne2DFloatArray

        public ABIStreamingEncoder encodeOne2DFloatArray​(float[][] data)
        Encode one 2D float array.
        Parameters:
        data - one 2D float array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_FLOAT
      • getLengthOfOne2DFloatArray

        public static int getLengthOfOne2DFloatArray​(float[][] data)
        Returns the length of the ABI encoding of this 2D float array.
        Parameters:
        data - one 2D float array
        Returns:
        the length of the ABI encoding of this 2D float array.
      • encodeOne2DLongArray

        public ABIStreamingEncoder encodeOne2DLongArray​(long[][] data)
        Encode one 2D long array.
        Parameters:
        data - one 2D long array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_LONG
      • getLengthOfOne2DLongArray

        public static int getLengthOfOne2DLongArray​(long[][] data)
        Returns the length of the ABI encoding of this 2D long array.
        Parameters:
        data - one 2D long array
        Returns:
        the length of the ABI encoding of this 2D long array.
      • encodeOne2DDoubleArray

        public ABIStreamingEncoder encodeOne2DDoubleArray​(double[][] data)
        Encode one 2D double array.
        Parameters:
        data - one 2D double array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by A_DOUBLE
      • getLengthOfOne2DDoubleArray

        public static int getLengthOfOne2DDoubleArray​(double[][] data)
        Returns the length of the ABI encoding of this 2D double array.
        Parameters:
        data - one 2D double array
        Returns:
        the length of the ABI encoding of this 2D double array.
      • encodeOneStringArray

        public ABIStreamingEncoder encodeOneStringArray​(java.lang.String[] data)
        Encode one string array.
        Parameters:
        data - one string array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by STRING
      • getLengthOfOneStringArray

        public static int getLengthOfOneStringArray​(java.lang.String[] data)
        Returns the length of the ABI encoding of this string array.
        Parameters:
        data - one string array
        Returns:
        the length of the ABI encoding of this string array.
      • encodeOneAddressArray

        public ABIStreamingEncoder encodeOneAddressArray​(Address[] data)
        Encode one address array.
        Parameters:
        data - one address array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by ADDRESS
      • encodeOneBigIntegerArray

        public ABIStreamingEncoder encodeOneBigIntegerArray​(java.math.BigInteger[] data)
        Encode one BigInteger array.
        Parameters:
        data - one BigInteger array
        Returns:
        the encoder with this element written into its buffer Null is encoded as the three identifiers: NULL, followed by ARRAY, followed by BIGINT
      • getLengthOfOneStringArray

        public static int getLengthOfOneStringArray​(Address[] data)
        Returns the length of the ABI encoding of this address array.
        Parameters:
        data - one address array
        Returns:
        the length of the ABI encoding of this address array.