Package org.aion.rlp
Class RLP
- java.lang.Object
-
- org.aion.rlp.RLP
-
public class RLP extends Object
- Author:
- Roman Mandeleil 2014, modified by aion 2017
-
-
Constructor Summary
Constructors Constructor Description RLP()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcalcElementPrefixSize(byte[] srcData)static DecodeResultdecode(byte[] data, int pos)Reads any RLP encoded byte-array and returns all objects as byte-array or list of byte-arraysstatic RLPListdecode2(byte[] msgData)Parse wire byte[] message into RLP elementsstatic RLPElementdecode2OneItem(byte[] msgData, int startPos)ImplNote Considers only encodings of one byte.static BigIntegerdecodeBigInteger(byte[] data, int index)static intdecodeInt(byte[] data, int index)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.static byte[]encodeBigInteger(BigInteger srcBigInteger)static byte[]encodeByte(byte singleByte)static byte[]encodeElement(byte[] srcData)static byte[]encodeInt(int singleInt)static byte[]encodeLength(int length, int offset)Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTHstatic byte[]encodeList(byte[]... elements)static byte[]encodeListHeader(int size)static byte[]encodeLong(long l)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.static byte[]encodeShort(short singleShort)static byte[]encodeString(String srcString)
-
-
-
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-arraypos- 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)
-
-