From 7f187674fc802c17b5035ef89ea99142a678fa27 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 27 Jan 2016 19:27:11 +0100 Subject: [PATCH] Fixed depth tracking --- util/src/rlp/rlpstream.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/src/rlp/rlpstream.rs b/util/src/rlp/rlpstream.rs index 0c7418a8b..0b600b567 100644 --- a/util/src/rlp/rlpstream.rs +++ b/util/src/rlp/rlpstream.rs @@ -25,6 +25,7 @@ impl ListInfo { pub struct RlpStream { unfinished_lists: ElasticArray16, encoder: BasicEncoder, + finished_list: bool, } impl Stream for RlpStream { @@ -32,6 +33,7 @@ impl Stream for RlpStream { RlpStream { unfinished_lists: ElasticArray16::new(), encoder: BasicEncoder::new(), + finished_list: false, } } @@ -42,15 +44,16 @@ impl Stream for RlpStream { } fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: Encodable { - let depth = self.unfinished_lists.len(); + self.finished_list = false; value.rlp_append(self); - if depth == self.unfinished_lists.len() { + if !self.finished_list { self.note_appended(1); } self } fn begin_list(&mut self, len: usize) -> &mut RlpStream { + self.finished_list = false; match len { 0 => { // we may finish, if the appended list len is equal 0 @@ -155,6 +158,7 @@ impl RlpStream { self.encoder.insert_list_len_at_pos(len, x.position); self.note_appended(1); } + self.finished_list = should_finish; } /// Drain the object and return the underlying ElasticArray.