Add prototype.
This commit is contained in:
parent
526f4b3a20
commit
2d556d6f06
21
src/rlp.rs
21
src/rlp.rs
@ -126,6 +126,12 @@ impl<'a> From<Rlp<'a>> for UntrustedRlp<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Prototype {
|
||||
Null,
|
||||
Data(usize),
|
||||
List(usize),
|
||||
}
|
||||
|
||||
impl<'a> Rlp<'a> {
|
||||
/// Create a new instance of `Rlp`
|
||||
pub fn new(bytes: &'a [u8]) -> Rlp<'a> {
|
||||
@ -134,6 +140,19 @@ impl<'a> Rlp<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the prototype of the RLP.
|
||||
pub fn prototype(&self) -> Prototype {
|
||||
if self.is_data() {
|
||||
Prototype::Data(self.size())
|
||||
}
|
||||
else if self.is_list() {
|
||||
Prototype::List(self.item_count())
|
||||
}
|
||||
else {
|
||||
Prototype::Null
|
||||
}
|
||||
}
|
||||
|
||||
/// The bare data of the rlp.
|
||||
///
|
||||
/// ```rust
|
||||
@ -148,7 +167,7 @@ impl<'a> Rlp<'a> {
|
||||
/// assert_eq!(dog, &[0x83, b'd', b'o', b'g']);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn data(&'a self) -> &'a [u8] {
|
||||
pub fn data(&self) -> &[u8] {
|
||||
self.rlp.data()
|
||||
}
|
||||
|
||||
|
13
src/trie.rs
13
src/trie.rs
@ -49,7 +49,7 @@ impl TrieDB {
|
||||
self.root = self.db.insert(root_data);
|
||||
}
|
||||
|
||||
fn insert(&mut self, key: &NibbleSlice, value: &[u8]) {
|
||||
fn add(&mut self, key: &NibbleSlice, value: &[u8]) {
|
||||
// determine what the new root is, insert new nodes and remove old as necessary.
|
||||
let mut todo: (Bytes, Diff);
|
||||
{
|
||||
@ -76,7 +76,8 @@ impl TrieDB {
|
||||
/// The database will be updated so as to make the returned RLP valid through inserting
|
||||
/// and deleting nodes as necessary.
|
||||
fn merge(&self, old: &[u8], partial_key: &NibbleSlice, value: &[u8]) -> (Bytes, Diff) {
|
||||
let o = Rlp::new(old);
|
||||
unimplemented!();
|
||||
/* let o = Rlp::new(old);
|
||||
match (o.type()) {
|
||||
List(17) => {
|
||||
// already have a branch. route and merge.
|
||||
@ -85,8 +86,8 @@ impl TrieDB {
|
||||
// already have an extension. either fast_forward, cleve or transmute_to_branch.
|
||||
},
|
||||
Data(0) => compose_extension(partial_key),
|
||||
_ -> panic!("Invalid RLP for node."),
|
||||
}
|
||||
_ => panic!("Invalid RLP for node."),
|
||||
}*/
|
||||
}
|
||||
|
||||
fn compose_extension(partial_key: &NibbleSlice, value: &[u8], is_leaf: bool) -> Bytes {
|
||||
@ -94,7 +95,7 @@ impl TrieDB {
|
||||
s.append(&partial_key.encoded(is_leaf));
|
||||
s.append(&value.to_vec()); // WTF?!?!
|
||||
//s.append(value); // <-- should be.
|
||||
s.out().unwrap()
|
||||
s.out()
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +111,7 @@ impl Trie for TrieDB {
|
||||
}
|
||||
|
||||
fn insert(&mut self, key: &[u8], value: &[u8]) {
|
||||
(self as &mut TrieDB).insert(&NibbleSlice::new(key), value);
|
||||
(self as &mut TrieDB).add(&NibbleSlice::new(key), value);
|
||||
}
|
||||
|
||||
fn remove(&mut self, _key: &[u8]) {
|
||||
|
Loading…
Reference in New Issue
Block a user