Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class Rlp
- Object
- Rlp
Recursive Length Prefix encoding as used by Ethereum. Items are either byte
arrays or lists of items. Decoding rejects every non-canonical form.
Methods
public static byte[] encode(Object item) | Encodes a byte array or a nested List of them. |
public static byte[] encodeLong(long value) | Encodes a non-negative long as a minimal big-endian byte string (zero is the empty string). |
public static byte[] encodeQuantity(UInt256 value) | Encodes a 256-bit quantity as a minimal big-endian byte string (zero is the empty string). |
public static byte[] longBytes(long value) | Returns the minimal big-endian bytes of a non-negative long, empty for zero. |
public static Object decode(byte[] data) | Decodes one RLP item that must span the whole input. |
Inherited methods
Method details
encode
public static byte[] encode(Object item)Encodes a byte array or a nested
List of them.Parameters
itemObject- a
byte[]or ajava.util.Listwhose elements are again either
Returns
the RLP bytes
Throws
IllegalArgumentException- if an element is neither a byte array nor a list
encodeLong
public static byte[] encodeLong(long value)Encodes a non-negative long as a minimal big-endian byte string (zero is the empty string).
Parameters
valuelong- a value of zero or more
Returns
the RLP bytes
encodeQuantity
public static byte[] encodeQuantity(UInt256 value)Encodes a 256-bit quantity as a minimal big-endian byte string (zero is the empty string).
Parameters
valueUInt256- the quantity
Returns
the RLP bytes
longBytes
public static byte[] longBytes(long value)Returns the minimal big-endian bytes of a non-negative long, empty for zero.
Parameters
valuelong- a value of zero or more
Returns
the unpadded bytes, for use as an RLP string item
decode
public static Object decode(byte[] data)Decodes one RLP item that must span the whole input.
Parameters
databyte[]- the RLP bytes
Returns
a
byte[] for a string or a java.util.List of decoded items for a listThrows
IllegalArgumentException- if the input is truncated, has trailing bytes or is not canonical