Class Rlp
java.lang.Object
com.codename1.crypto.encoding.Rlp
Recursive Length Prefix encoding as used by Ethereum. Items are either byte
arrays or lists of items. Decoding rejects every non-canonical form.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Objectdecode(byte[] data) Decodes one RLP item that must span the whole input.static byte[]Encodes a byte array or a nestedListof them.static byte[]encodeLong(long value) Encodes a non-negative long as a minimal big-endian byte string (zero is the empty string).static byte[]encodeQuantity(UInt256 value) Encodes a 256-bit quantity as a minimal big-endian byte string (zero is the empty string).static byte[]longBytes(long value) Returns the minimal big-endian bytes of a non-negative long, empty for zero.
-
Method Details
-
encode
-
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
value: a value of zero or more
Returns
the RLP bytes
-
encodeQuantity
Encodes a 256-bit quantity as a minimal big-endian byte string (zero is the empty string).
Parameters
value: 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
value: a value of zero or more
Returns
the unpadded bytes, for use as an RLP string item
-
decode
Decodes one RLP item that must span the whole input.
Parameters
data: the RLP bytes
Returns
a
byte[]for a string or ajava.util.Listof decoded items for a listThrows
IllegalArgumentException: if the input is truncated, has trailing bytes or is not canonical
-