rlp items functions
This commit is contained in:
parent
80f1e527dc
commit
b6dc3e464d
39
src/rlp.rs
39
src/rlp.rs
@ -152,6 +152,24 @@ impl<'a> Rlp<'a> {
|
|||||||
self.rlp.data()
|
self.rlp.data()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns number of rlp items.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// extern crate ethcore_util as util;
|
||||||
|
/// use util::rlp::*;
|
||||||
|
///
|
||||||
|
/// fn main () {
|
||||||
|
/// let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
|
||||||
|
/// let rlp = Rlp::new(&data);
|
||||||
|
/// assert_eq!(rlp.items(), 2);
|
||||||
|
/// let view = rlp.at(1);
|
||||||
|
/// assert_eq!(view.items(), 0);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn items(&self) -> usize {
|
||||||
|
self.rlp.items()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get view onto rlp-slice at index.
|
/// Get view onto rlp-slice at index.
|
||||||
///
|
///
|
||||||
/// Caches offset to given index, so access to successive
|
/// Caches offset to given index, so access to successive
|
||||||
@ -297,6 +315,27 @@ impl<'a> UntrustedRlp<'a> {
|
|||||||
self.bytes
|
self.bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns number of rlp items.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// extern crate ethcore_util as util;
|
||||||
|
/// use util::rlp::*;
|
||||||
|
///
|
||||||
|
/// fn main () {
|
||||||
|
/// let data = vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g'];
|
||||||
|
/// let rlp = UntrustedRlp::new(&data);
|
||||||
|
/// assert_eq!(rlp.items(), 2);
|
||||||
|
/// let view = rlp.at(1).unwrap();
|
||||||
|
/// assert_eq!(view.items(), 0);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn items(&self) -> usize {
|
||||||
|
match self.is_list() {
|
||||||
|
true => self.iter().count(),
|
||||||
|
false => 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get view onto rlp-slice at index
|
/// Get view onto rlp-slice at index
|
||||||
///
|
///
|
||||||
/// Caches offset to given index, so access to successive
|
/// Caches offset to given index, so access to successive
|
||||||
|
Loading…
Reference in New Issue
Block a user