RlpStream manipulation

I want to do some manipulation on RlpStream manually. But I am confused how it work. For example considered following program;

extern crate rlp;
use rlp::*;

fn main () {
let name = "amir";
let age: u8 = 38;
let fname = "ali";
let mut stream = RlpStream::new_list(3);
stream.append(&name).append(&age).append(&fname);
let out = stream.drain();
println!("My RlpStream : {:?}",out);
}

The output of above programe is :

My RlpStream : [202, 132, 97, 109, 105, 114, 38, 131, 97, 108, 105]

as you can see there are 11 bytes in rlp list, whereas my code has 8 byte [i.e. "amir" = 4 bytes, age=38 = 1 byte, and "ali"=3 bytes]. I know amir=97, 109, 105, 114, age = 38 and ali=97, 108, 105... then why and how 202, 132, and 131 are inserted ????? If we want to calculate these bytes manually, is there any method/formula ????
Making it more complex, if I want to insert a structure type variable (say i.e. Student (name, class, roll no, etc..) then how these bytes are calculated ?

They are exactly "Recursive Length Prefix"es, right? This is the first time I heard the encoding scheme, but according to https://github.com/ethereum/wiki/wiki/RLP, 202 (0xCA = 0xC0 + 10), 132 (0x84 = 0x80 + 4), and 131 (0x83 = 0x80 + 3) represent the length of total RLP payload, the length of "amir", and the length of "ali" respectively.

(That said, I think this is off topic of Rust language forum. Ethereum community may be more helpful regarding their technologies.)

@sinkuu thanks for your detailed answer... but for age is there no need for such lenght information ? if there is variable whose length is about u64, even then such information (about length related) would be needed or not ?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.