decoder refactor applied
This commit is contained in:
@@ -37,4 +37,14 @@ pub mod rlp;
|
||||
pub mod untrusted_rlp;
|
||||
pub mod rlpstream;
|
||||
|
||||
pub use self::old::*;
|
||||
pub use self::faces::{DecoderError, Decoder, Decodable, View};
|
||||
pub use self::rlp::*;
|
||||
pub use self::untrusted_rlp::*;
|
||||
|
||||
pub use self::old::{encode, RlpStream, Encodable};
|
||||
//pub use self::old::*;
|
||||
|
||||
pub fn decode<T>(bytes: &[u8]) -> T where T: Decodable {
|
||||
let rlp = Rlp::new(bytes);
|
||||
rlp.as_val()
|
||||
}
|
||||
|
||||
@@ -1119,7 +1119,7 @@ mod tests {
|
||||
use std::{fmt, cmp};
|
||||
use std::str::FromStr;
|
||||
use rlp;
|
||||
use rlp::{UntrustedRlp, RlpStream, Decodable};
|
||||
use rlp::{UntrustedRlp, RlpStream, Decodable, View};
|
||||
use uint::U256;
|
||||
|
||||
#[test]
|
||||
@@ -1128,23 +1128,27 @@ mod tests {
|
||||
{
|
||||
let rlp = UntrustedRlp::new(&data);
|
||||
assert!(rlp.is_list());
|
||||
let animals = <Vec<String> as rlp::Decodable>::decode_untrusted(&rlp).unwrap();
|
||||
//let animals = <Vec<String> as rlp::Decodable>::decode_untrusted(&rlp).unwrap();
|
||||
let animals: Vec<String> = rlp.as_val().unwrap();
|
||||
assert_eq!(animals, vec!["cat".to_string(), "dog".to_string()]);
|
||||
|
||||
let cat = rlp.at(0).unwrap();
|
||||
assert!(cat.is_data());
|
||||
assert_eq!(cat.bytes, &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat.raw(), &[0x83, b'c', b'a', b't']);
|
||||
//assert_eq!(String::decode_untrusted(&cat).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat.as_val::<String>().unwrap(), "cat".to_string());
|
||||
|
||||
let dog = rlp.at(1).unwrap();
|
||||
assert!(dog.is_data());
|
||||
assert_eq!(dog.bytes, &[0x83, b'd', b'o', b'g']);
|
||||
assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_string());
|
||||
assert_eq!(dog.raw(), &[0x83, b'd', b'o', b'g']);
|
||||
//assert_eq!(String::decode_untrusted(&dog).unwrap(), "dog".to_string());
|
||||
assert_eq!(dog.as_val::<String>().unwrap(), "dog".to_string());
|
||||
|
||||
let cat_again = rlp.at(0).unwrap();
|
||||
assert!(cat_again.is_data());
|
||||
assert_eq!(cat_again.bytes, &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat_again.raw(), &[0x83, b'c', b'a', b't']);
|
||||
//assert_eq!(String::decode_untrusted(&cat_again).unwrap(), "cat".to_string());
|
||||
assert_eq!(cat_again.as_val::<String>().unwrap(), "cat".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1172,18 +1176,18 @@ mod tests {
|
||||
|
||||
let cat = iter.next().unwrap();
|
||||
assert!(cat.is_data());
|
||||
assert_eq!(cat.bytes, &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat.raw(), &[0x83, b'c', b'a', b't']);
|
||||
|
||||
let dog = iter.next().unwrap();
|
||||
assert!(dog.is_data());
|
||||
assert_eq!(dog.bytes, &[0x83, b'd', b'o', b'g']);
|
||||
assert_eq!(dog.raw(), &[0x83, b'd', b'o', b'g']);
|
||||
|
||||
let none = iter.next();
|
||||
assert!(none.is_none());
|
||||
|
||||
let cat_again = rlp.at(0).unwrap();
|
||||
assert!(cat_again.is_data());
|
||||
assert_eq!(cat_again.bytes, &[0x83, b'c', b'a', b't']);
|
||||
assert_eq!(cat_again.raw(), &[0x83, b'c', b'a', b't']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user