in many standard documentation and many blogs, I have found the example for list with two strings like below
[“cat”, “dog” ] -> C8 83 636174 83 646F67
and thats how it is decoded 1) Retrieve the first byte : 0xc8 2) Find the closest Byte Range which the first byte falls within; In this case, the First byte falls within the range [0xc0 .. 0xf7] hence the data is a List. 3) Create an empty List [] to accumulate 4) Length of the list, [0xc8 -0xc0] = 8 5) Start deciphering after c8 to get the encoded data from the List until end of List. C8 83 63 61 74 83 64 6F 67
We know we have a list [ and it has eight elements], now let’s look at what’s inside the List.
6) Figure out length which is: first byte-range, 0x83–0x80 = 3 7) The data type is String, and its length is 3 8) Parse and decipher the next 3 bytes 0x63, 0x61, 0x74 9) Repeat Steps 6 through 8 until end of the list for the next set of bytes resulting in 0x83, 0x64, 0x6f, 0x67
10) Calculate the Length and interpret the data, in this case, the data is 0x64,0x6f,0x67.
Every thing looks good and as per the RLP documentation But
I was wondering how we will decode if the example will be something like below
[131, “dog”, “cat”]
1) It is a list so start 0xc0 2) 131 → 0x83 , 3) dog to byte string → [0x80+3, 0x63, 0x61, 0x74] 4) cat to byte string → [0x80+3, 0x64, 0x6F, 0x67]
Final encoding → [0xc7, 0x83, 0x83, 0x63, 0x61, 0x74, 0x83, 0x64, 0x6F, 0x67]
Now during decoding → 0xc7 — indicate that it’s a list → list length is 7 (0xc7–0xc0) → Now what 0x83 should be assumed it could indicate that its is a byte string with 3 length or is it a number 131 which has a hex value 0x83 →