3

Hi!
I have some data, like this ( 827ab7 ), encoding RLP.
How I can to know, what is it (string, list or int)?

2 Answers 2

3

The other answer gives useful information, but to directly answer your question: RLP encoding does not give any information about types. It only encodes strings (byte sequences) and lists of lists/strings. How you interpret those strings (byte sequences) is up to the application.

3
  • RLP encodes byte arrays, arrays of byte arrays, and tree structures of byte arrays. Commented Apr 17, 2018 at 21:30
  • By a "tree structure of byte arrays," do you mean something other than "lists of lists," which I mentioned in my answer already?
    – user19510
    Commented Apr 18, 2018 at 0:43
  • I meant that it is a recursive data structure with no limitations on the depth that it can represent. But I guess list of lists can also be interpreted this way. Commented Apr 18, 2018 at 8:57
1

RLP encoding is defined as follows:

  • For a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.

  • Otherwise, if a string is 0-55 bytes long, the RLP encoding consists of a single byte with value 0x80 plus the length of the string followed by the string. The range of the first byte is thus [0x80, 0xb7].

  • If a string is more than 55 bytes long, the RLP encoding consists of a single byte with value 0xb7 plus the length in bytes of the length of the string in binary form, followed by the length of the string, followed by the string. For example, a length-1024 string would be encoded as \xb9\x04\x00 followed by the string. The range of the first byte is thus [0xb8, 0xbf].

  • If the total payload of a list (i.e. the combined length of all its items being RLP encoded) is 0-55 bytes long, the RLP encoding consists of a single byte with value 0xc0 plus the length of the list followed by the concatenation of the RLP encodings of the items. The range of the first byte is thus [0xc0, 0xf7].

  • If the total payload of a list is more than 55 bytes long, the RLP encoding consists of a single byte with value 0xf7 plus the length in bytes of the length of the payload in binary form, followed by the length of the payload, followed by the concatenation of the RLP encodings of the items. The range of the first byte is thus [0xf8, 0xff].


So, answering your question: just look at first byte of your data and use the information above

82 7ab7

.


RLP wiki


2
  • I am looking at first byte and ...?! how i can to know what type is (string or int)?
    – Andrey
    Commented Jan 1, 2018 at 21:16
  • There is no type difference when you encoded data with RLP. You are encoding hexadecimal value, so the only difference is if it’s a single byte, string or a list. Commented Jan 1, 2018 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.