Additional bloom-related functionality.

RlpStandard for non-emit_*-based RlpStream extesions.
This commit is contained in:
Gav Wood
2016-01-09 23:47:46 +01:00
parent 568d28e94b
commit ffc28bf495
4 changed files with 39 additions and 19 deletions

View File

@@ -43,7 +43,7 @@ pub use self::rlperrors::DecoderError;
pub use self::rlptraits::{Decoder, Decodable, View, Stream, Encodable, Encoder};
pub use self::untrusted_rlp::{UntrustedRlp, UntrustedRlpIterator, PayloadInfo, Prototype};
pub use self::rlpin::{Rlp, RlpIterator};
pub use self::rlpstream::{RlpStream};
pub use self::rlpstream::{RlpStream,RlpStandard};
use super::hash::H256;
pub const NULL_RLP: [u8; 1] = [0x80; 1];

View File

@@ -1,6 +1,8 @@
use elastic_array::*;
use bytes::ToBytes;
use bytes::{Bytes, ToBytes};
use rlp::{Stream, Encoder, Encodable};
use hash::H256;
use sha3::*;
#[derive(Debug, Copy, Clone)]
struct ListInfo {
@@ -213,6 +215,20 @@ impl Encoder for BasicEncoder {
}
}
pub trait RlpStandard {
fn rlp_append(&self, s: &mut RlpStream);
fn rlp_bytes(&self) -> Bytes {
let mut s = RlpStream::new();
self.rlp_append(&mut s);
s.out()
}
fn rlp_sha3(&self) -> H256 { self.rlp_bytes().sha3() }
}
// @debris TODO: implement Encoder for RlpStandard.
impl<T> Encodable for T where T: ToBytes {
fn encode<E>(&self, encoder: &mut E) where E: Encoder {
encoder.emit_value(&self.to_bytes())