openethereum/util/rlp/src/rlptraits.rs

374 lines
9.5 KiB
Rust
Raw Normal View History

2016-12-11 19:30:54 +01:00
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
2016-02-05 13:40:41 +01:00
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
2016-01-29 13:59:29 +01:00
//! Common RLP traits
use ::{DecoderError, UntrustedRlp};
use bytes::VecLike;
use rlpstream::RlpStream;
2016-01-27 12:14:57 +01:00
use elastic_array::ElasticArray1024;
2015-12-08 00:07:07 +01:00
/// Type is able to decode RLP.
2015-12-14 12:03:48 +01:00
pub trait Decoder: Sized {
/// Read a value from the RLP into a given type.
Blocks and snapshot compression (#1687) * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * new Compressible rlp trait * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * new Compressible rlp trait * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * DecompressingDecoder test * initial compressing HashDB wrapper * remove unused test * change CompressedDB to struct wrapper with overlay * simplify compressor * failed RefCell attempt * use denote to return reference * compiled compresseddb * compressdb test, add overlay emplace * fix overlay reference count handling * add immutable compresseddb, make account use hashdb * simplify using trait objects * enable hashdb for account * initial state compression attempt * wrap state db * add tests for analyzing db * add account predicate * try to compress data fields as rlp too * remove compression for storage trie * add a compressing migration * more compression stats tests * fix migration import * nested encoding compression test * fix decompression, move db stats tests to rlpcompression * added malformed rlp tests, cover a few edge cases * new CompressingEncoder struct * extend migrations to state * first version working on the whole db * clean up Compressible impl * tests cleanup * add a testing migration * refactor deep compression using option, add simple compression * put tests in a module * fix compressed overlay loading * simple compression for snapshots * remove unused DecompressingDecoder * add a general compressing migration * add more common rlps to compress * use static slices for swapper * add precomputed hashes and invalid rlps * make decoder private again * cover more cases with tests * style * fix weird indentation * remove possible panic in payload_info * make prefix checking safe * fix db existence check * remove db dir from test * pass usize by value [ci skip] * Improve comment on panic removal. * add common blocks db rlps * add compression to blockchain db * add blocks db migration * fix the migrations * remove state compression * add a separate snapshot swapper * ability to use different swappers and traversal * update tests to new interface * clean up code ordering * update usage * fix compilation * remove unnecessary changes * move methods to functions to reduce interface * move test to module * update common rlps to blocks db * move tests to tests modules * remove redundant &
2016-07-27 17:11:41 +02:00
fn read_value<T, F>(&self, f: &F) -> Result<T, DecoderError>
where F: Fn(&[u8]) -> Result<T, DecoderError>;
2015-12-07 23:47:26 +01:00
/// Get underlying `UntrustedRLP` object.
2016-01-19 12:14:29 +01:00
fn as_rlp(&self) -> &UntrustedRlp;
/// Get underlying raw bytes slice.
fn as_raw(&self) -> &[u8];
2015-12-07 23:47:26 +01:00
}
2016-01-29 13:59:29 +01:00
/// RLP decodable trait
2015-12-07 23:47:26 +01:00
pub trait Decodable: Sized {
2016-01-29 13:59:29 +01:00
/// Decode a value from RLP bytes
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder;
}
/// Internal helper trait. Implement `Decodable` for custom types.
pub trait RlpDecodable: Sized {
/// Decode a value from RLP bytes
2015-12-08 00:27:12 +01:00
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder;
2015-12-07 23:47:26 +01:00
}
2016-02-03 16:43:48 +01:00
/// A view into RLP encoded data
2015-12-07 23:47:26 +01:00
pub trait View<'a, 'view>: Sized {
2016-02-03 16:43:48 +01:00
/// RLP prototype type
2015-12-07 16:32:06 +01:00
type Prototype;
2016-02-03 16:43:48 +01:00
/// Payload info type
2015-12-07 16:32:06 +01:00
type PayloadInfo;
2016-02-03 16:43:48 +01:00
/// Data type
2015-12-07 16:32:06 +01:00
type Data;
2016-02-03 16:43:48 +01:00
/// Item type
2015-12-07 16:32:06 +01:00
type Item;
2016-02-03 16:43:48 +01:00
/// Iterator type
2015-12-07 23:47:26 +01:00
type Iter;
2015-12-07 16:32:06 +01:00
2015-12-07 23:47:26 +01:00
/// Creates a new instance of `Rlp` reader
2015-12-07 16:32:06 +01:00
fn new(bytes: &'a [u8]) -> Self;
2015-12-07 23:47:26 +01:00
Blocks and snapshot compression (#1687) * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * new Compressible rlp trait * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * new Compressible rlp trait * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * DecompressingDecoder test * initial compressing HashDB wrapper * remove unused test * change CompressedDB to struct wrapper with overlay * simplify compressor * failed RefCell attempt * use denote to return reference * compiled compresseddb * compressdb test, add overlay emplace * fix overlay reference count handling * add immutable compresseddb, make account use hashdb * simplify using trait objects * enable hashdb for account * initial state compression attempt * wrap state db * add tests for analyzing db * add account predicate * try to compress data fields as rlp too * remove compression for storage trie * add a compressing migration * more compression stats tests * fix migration import * nested encoding compression test * fix decompression, move db stats tests to rlpcompression * added malformed rlp tests, cover a few edge cases * new CompressingEncoder struct * extend migrations to state * first version working on the whole db * clean up Compressible impl * tests cleanup * add a testing migration * refactor deep compression using option, add simple compression * put tests in a module * fix compressed overlay loading * simple compression for snapshots * remove unused DecompressingDecoder * add a general compressing migration * add more common rlps to compress * use static slices for swapper * add precomputed hashes and invalid rlps * make decoder private again * cover more cases with tests * style * fix weird indentation * remove possible panic in payload_info * make prefix checking safe * fix db existence check * remove db dir from test * pass usize by value [ci skip] * Improve comment on panic removal. * add common blocks db rlps * add compression to blockchain db * add blocks db migration * fix the migrations * remove state compression * add a separate snapshot swapper * ability to use different swappers and traversal * update tests to new interface * clean up code ordering * update usage * fix compilation * remove unnecessary changes * move methods to functions to reduce interface * move test to module * update common rlps to blocks db * move tests to tests modules * remove redundant &
2016-07-27 17:11:41 +02:00
/// The raw data of the RLP as slice.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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);
2016-01-08 15:52:43 +01:00
/// let dog = rlp.at(1).as_raw();
2015-12-07 23:47:26 +01:00
/// assert_eq!(dog, &[0x83, b'd', b'o', b'g']);
/// }
/// ```
2016-01-08 15:52:43 +01:00
fn as_raw(&'view self) -> &'a [u8];
2015-12-07 23:47:26 +01:00
/// Get the prototype of the RLP.
2015-12-07 16:32:06 +01:00
fn prototype(&self) -> Self::Prototype;
2015-12-07 23:47:26 +01:00
2016-02-03 16:43:48 +01:00
/// Get payload info.
2015-12-07 16:32:06 +01:00
fn payload_info(&self) -> Self::PayloadInfo;
2015-12-07 23:47:26 +01:00
2016-02-03 16:43:48 +01:00
/// Get underlieing data.
2015-12-07 16:32:06 +01:00
fn data(&'view self) -> Self::Data;
2015-12-07 23:47:26 +01:00
/// Returns number of RLP items.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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.item_count(), 2);
/// let view = rlp.at(1);
/// assert_eq!(view.item_count(), 0);
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn item_count(&self) -> usize;
2015-12-07 23:47:26 +01:00
/// Returns the number of bytes in the data, or zero if it isn't data.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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.size(), 0);
/// let view = rlp.at(1);
/// assert_eq!(view.size(), 3);
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn size(&self) -> usize;
2015-12-07 23:47:26 +01:00
/// Get view onto RLP-slice at index.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// Caches offset to given index, so access to successive
/// slices is faster.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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);
2015-12-08 12:40:11 +01:00
/// let dog: String = rlp.at(1).as_val();
2015-12-07 23:47:26 +01:00
/// assert_eq!(dog, "dog".to_string());
/// }
2015-12-07 16:32:06 +01:00
fn at(&'view self, index: usize) -> Self::Item;
2015-12-07 23:47:26 +01:00
/// No value
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// fn main () {
/// let data = vec![];
/// let rlp = Rlp::new(&data);
/// assert!(rlp.is_null());
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn is_null(&self) -> bool;
2015-12-07 23:47:26 +01:00
/// Contains a zero-length string or zero-length list.
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// fn main () {
/// let data = vec![0xc0];
/// let rlp = Rlp::new(&data);
/// assert!(rlp.is_empty());
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn is_empty(&self) -> bool;
2015-12-07 23:47:26 +01:00
/// List value
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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!(rlp.is_list());
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn is_list(&self) -> bool;
2015-12-07 23:47:26 +01:00
/// String value
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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!(rlp.at(1).is_data());
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn is_data(&self) -> bool;
2015-12-07 23:47:26 +01:00
/// Int value
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// fn main () {
/// let data = vec![0xc1, 0x10];
/// let rlp = Rlp::new(&data);
/// assert_eq!(rlp.is_int(), false);
/// assert_eq!(rlp.at(0).is_int(), true);
/// }
/// ```
2015-12-07 16:32:06 +01:00
fn is_int(&self) -> bool;
2015-12-07 23:47:26 +01:00
/// Get iterator over rlp-slices
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
2015-12-07 23:47:26 +01:00
/// 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);
2015-12-08 12:40:11 +01:00
/// let strings: Vec<String> = rlp.iter().map(| i | i.as_val()).collect();
2015-12-07 23:47:26 +01:00
/// }
/// ```
fn iter(&'view self) -> Self::Iter;
2016-02-03 16:43:48 +01:00
/// Decode data into an object
2016-01-29 13:59:29 +01:00
fn as_val<T>(&self) -> Result<T, DecoderError> where T: RlpDecodable;
2015-12-08 14:44:22 +01:00
2016-02-03 16:43:48 +01:00
/// Decode data at given list index into an object
2016-01-29 13:59:29 +01:00
fn val_at<T>(&self, index: usize) -> Result<T, DecoderError> where T: RlpDecodable;
2015-12-07 23:47:26 +01:00
}
2016-02-03 16:43:48 +01:00
/// Raw RLP encoder
2015-12-07 23:47:26 +01:00
pub trait Encoder {
2016-02-03 16:43:48 +01:00
/// Write a value represented as bytes
2016-01-27 12:14:57 +01:00
fn emit_value<E: ByteEncodable>(&mut self, value: &E);
2016-02-03 16:43:48 +01:00
/// Write raw preencoded data to the output
fn emit_raw(&mut self, bytes: &[u8]) -> ();
2015-12-07 23:47:26 +01:00
}
2016-01-27 12:14:57 +01:00
/// Primitive data type encodable to RLP
pub trait ByteEncodable {
/// Serialize this object to given byte container
fn to_bytes<V: VecLike<u8>>(&self, out: &mut V);
/// Get size of serialised data in bytes
fn bytes_len(&self) -> usize;
}
/// Structure encodable to RLP. Implement this trait for
2015-12-07 23:47:26 +01:00
pub trait Encodable {
2016-01-27 12:14:57 +01:00
/// Append a value to the stream
fn rlp_append(&self, s: &mut RlpStream);
/// Get rlp-encoded bytes for this instance
fn rlp_bytes(&self) -> ElasticArray1024<u8> {
let mut s = RlpStream::new();
self.rlp_append(&mut s);
s.drain()
}
2015-12-07 16:32:06 +01:00
}
2016-01-28 20:13:05 +01:00
/// Encodable wrapper trait required to handle special case of encoding a &[u8] as string and not as list
pub trait RlpEncodable {
/// Append a value to the stream
fn rlp_append(&self, s: &mut RlpStream);
}
2016-02-03 16:43:48 +01:00
/// RLP encoding stream
2015-12-07 23:47:26 +01:00
pub trait Stream: Sized {
/// Initializes instance of empty `Stream`.
2015-12-07 23:47:26 +01:00
fn new() -> Self;
/// Initializes the `Stream` as a list.
2015-12-07 23:47:26 +01:00
fn new_list(len: usize) -> Self;
/// Apends value to the end of stream, chainable.
///
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
/// fn main () {
/// let mut stream = RlpStream::new_list(2);
/// stream.append(&"cat").append(&"dog");
/// let out = stream.out();
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
/// }
/// ```
2016-01-28 20:13:05 +01:00
fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: RlpEncodable;
/// Declare appending the list of given size, chainable.
///
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
/// fn main () {
/// let mut stream = RlpStream::new_list(2);
2016-01-27 12:14:57 +01:00
/// stream.begin_list(2).append(&"cat").append(&"dog");
2015-12-26 15:48:41 +01:00
/// stream.append(&"");
/// let out = stream.out();
/// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
/// }
/// ```
2016-01-27 12:14:57 +01:00
fn begin_list(&mut self, len: usize) -> &mut Self;
/// Apends null to the end of stream, chainable.
///
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
/// fn main () {
/// let mut stream = RlpStream::new_list(2);
/// stream.append_empty_data().append_empty_data();
/// let out = stream.out();
/// assert_eq!(out, vec![0xc2, 0x80, 0x80]);
/// }
/// ```
2016-01-19 12:14:29 +01:00
fn append_empty_data(&mut self) -> &mut Self;
/// Appends raw (pre-serialised) RLP data. Use with caution. Chainable.
fn append_raw<'a>(&'a mut self, bytes: &[u8], item_count: usize) -> &'a mut Self;
/// Clear the output stream so far.
2015-12-26 15:48:41 +01:00
///
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
/// fn main () {
/// let mut stream = RlpStream::new_list(3);
/// stream.append(&"cat");
/// stream.clear();
/// stream.append(&"dog");
/// let out = stream.out();
/// assert_eq!(out, vec![0x83, b'd', b'o', b'g']);
/// }
fn clear(&mut self);
/// Returns true if stream doesnt expect any more items.
///
/// ```rust
/// extern crate rlp;
/// use rlp::*;
2015-12-26 15:48:41 +01:00
///
/// fn main () {
/// let mut stream = RlpStream::new_list(2);
/// stream.append(&"cat");
/// assert_eq!(stream.is_finished(), false);
/// stream.append(&"dog");
/// assert_eq!(stream.is_finished(), true);
/// let out = stream.out();
/// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
/// }
fn is_finished(&self) -> bool;
2016-02-03 16:43:48 +01:00
/// Get raw encoded bytes
2016-01-08 15:57:50 +01:00
fn as_raw(&self) -> &[u8];
/// Streams out encoded bytes.
2015-12-26 15:48:41 +01:00
///
/// panic! if stream is not finished.
fn out(self) -> Vec<u8>;
2015-12-07 16:32:06 +01:00
}
Blocks and snapshot compression (#1687) * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * new Compressible rlp trait * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * new Compressible rlp trait * new Compressible rlp trait * new Compressible rlp trait * make compressed rlp iterable * make compressed rlp iterable * make compressed rlp iterable * invalid rlp slice swapper * invalid rlp slice swapper * invalid rlp slice swapper * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * switch compress to swapper, add reverse swapper test case * add basic account compression test * add new rlp trait * add account compress/ decompress test * make compressor cleaner, use hashmaps for swapper * improve compression tests * add a DecompressingDecoder, change Decoder to take refernce * separate rlp compression related stuff * DecompressingDecoder test * initial compressing HashDB wrapper * remove unused test * change CompressedDB to struct wrapper with overlay * simplify compressor * failed RefCell attempt * use denote to return reference * compiled compresseddb * compressdb test, add overlay emplace * fix overlay reference count handling * add immutable compresseddb, make account use hashdb * simplify using trait objects * enable hashdb for account * initial state compression attempt * wrap state db * add tests for analyzing db * add account predicate * try to compress data fields as rlp too * remove compression for storage trie * add a compressing migration * more compression stats tests * fix migration import * nested encoding compression test * fix decompression, move db stats tests to rlpcompression * added malformed rlp tests, cover a few edge cases * new CompressingEncoder struct * extend migrations to state * first version working on the whole db * clean up Compressible impl * tests cleanup * add a testing migration * refactor deep compression using option, add simple compression * put tests in a module * fix compressed overlay loading * simple compression for snapshots * remove unused DecompressingDecoder * add a general compressing migration * add more common rlps to compress * use static slices for swapper * add precomputed hashes and invalid rlps * make decoder private again * cover more cases with tests * style * fix weird indentation * remove possible panic in payload_info * make prefix checking safe * fix db existence check * remove db dir from test * pass usize by value [ci skip] * Improve comment on panic removal. * add common blocks db rlps * add compression to blockchain db * add blocks db migration * fix the migrations * remove state compression * add a separate snapshot swapper * ability to use different swappers and traversal * update tests to new interface * clean up code ordering * update usage * fix compilation * remove unnecessary changes * move methods to functions to reduce interface * move test to module * update common rlps to blocks db * move tests to tests modules * remove redundant &
2016-07-27 17:11:41 +02:00
/// Trait for compressing and decompressing RLP by replacement of common terms.
pub trait Compressible: Sized {
/// Indicates the origin of RLP to be compressed.
type DataType;
/// Compress given RLP type using appropriate methods.
fn compress(&self, t: Self::DataType) -> ElasticArray1024<u8>;
/// Decompress given RLP type using appropriate methods.
fn decompress(&self, t: Self::DataType) -> ElasticArray1024<u8>;
}