From 15820887595077fb92350221b5e0a72e7caa510d Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 26 Nov 2015 00:37:53 +0100 Subject: [PATCH] rlp encoding documentation --- src/rlp.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/rlp.rs b/src/rlp.rs index 3cb240734..e5ac25799 100644 --- a/src/rlp.rs +++ b/src/rlp.rs @@ -1,4 +1,47 @@ //! Rlp serialization module +//! +//! Types implementing `Endocable` and `Decodable` traits +//! can be easily coverted to and from rlp +//! +//! # Examples: +//! +//! ```rust +//! extern crate ethcore_util; +//! use ethcore_util::rlp::{RlpStream}; +//! +//! fn encode_value() { +//! // 1029 +//! let mut stream = RlpStream::new(); +//! stream.append(&1029u32); +//! let out = stream.out().unwrap(); +//! assert_eq!(out, vec![0x82, 0x04, 0x05]); +//! } +//! +//! fn encode_list() { +//! // [ "cat", "dog" ] +//! let mut stream = RlpStream::new_list(2); +//! stream.append(&"cat").append(&"dog"); +//! let out = stream.out().unwrap(); +//! assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); +//! } +//! +//! fn encode_list2() { +//! // [ [], [[]], [ [], [[]] ] ] +//! let mut stream = RlpStream::new_list(3); +//! stream.append_list(0); +//! stream.append_list(1).append_list(0); +//! stream.append_list(2).append_list(0).append_list(1).append_list(0); +//! let out = stream.out().unwrap(); +//! assert_eq!(out, vec![0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]); +//! } +//! +//! fn main() { +//! encode_value(); +//! encode_list(); +//! encode_list2(); +//! } +//! ``` +//! use std::fmt; use std::cell::Cell;