Package org.aion.rlp

Class RLP


  • public class RLP
    extends Object
    Author:
    Roman Mandeleil 2014, modified by aion 2017
    • Constructor Detail

      • RLP

        public RLP()
    • Method Detail

      • decodeInt

        public static int decodeInt​(byte[] data,
                                    int index)
      • decodeBigInteger

        public static BigInteger decodeBigInteger​(byte[] data,
                                                  int index)
      • decode2

        public static RLPList decode2​(byte[] msgData)
        Parse wire byte[] message into RLP elements
        Parameters:
        msgData - - raw RLP data
        Returns:
        rlpList - outcome of recursive RLP structure
      • decode2OneItem

        public static RLPElement decode2OneItem​(byte[] msgData,
                                                int startPos)
        ImplNote Considers only encodings of one byte.
      • decode

        public static DecodeResult decode​(byte[] data,
                                          int pos)
        Reads any RLP encoded byte-array and returns all objects as byte-array or list of byte-arrays
        Parameters:
        data - RLP encoded byte-array
        pos - position in the array to start reading
        Returns:
        DecodeResult encapsulates the decoded items as a single Object and the final read position
      • encode

        public static byte[] encode​(Object input)
        Turn Object into its RLP encoded equivalent of a byte-array Support for String, Integer, BigInteger and Lists of any of these types.
        Parameters:
        input - as object or List of objects
        Returns:
        byte[] RLP encoded
      • encodeLength

        public static byte[] encodeLength​(int length,
                                          int offset)
        Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH
      • encodeByte

        public static byte[] encodeByte​(byte singleByte)
      • encodeShort

        public static byte[] encodeShort​(short singleShort)
      • encodeInt

        public static byte[] encodeInt​(int singleInt)
      • encodeLong

        public static byte[] encodeLong​(long l)
      • encodeString

        public static byte[] encodeString​(String srcString)
      • encodeBigInteger

        public static byte[] encodeBigInteger​(BigInteger srcBigInteger)
      • encodeElement

        public static byte[] encodeElement​(byte[] srcData)
      • calcElementPrefixSize

        public static int calcElementPrefixSize​(byte[] srcData)
      • encodeListHeader

        public static byte[] encodeListHeader​(int size)
      • encodeLongElementHeader

        public static byte[] encodeLongElementHeader​(int length)
        ImplNote The interpretation of long element here is anything that requires an non-empty header and is not a list.
      • encodeList

        public static byte[] encodeList​(byte[]... elements)