Class Rlp

java.lang.Object
com.codename1.crypto.encoding.Rlp

public final class Rlp extends Object
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 Type
    Method
    Description
    static Object
    decode(byte[] data)
    Decodes one RLP item that must span the whole input.
    static byte[]
    encode(Object item)
    Encodes a byte array or a nested List of 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[]
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encode

      public static byte[] encode(Object item)

      Encodes a byte array or a nested List of them.

      Parameters
      • item: a byte[] or a java.util.List whose 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
      • value: 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
      • 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

      public static Object decode(byte[] data)

      Decodes one RLP item that must span the whole input.

      Parameters
      • data: the RLP bytes
      Returns

      a byte[] for a string or a java.util.List of decoded items for a list

      Throws
      • IllegalArgumentException: if the input is truncated, has trailing bytes or is not canonical