Update SSZ
- Implement generic list decoding> - Expose `encode` mod. - Add convenience encoding function.
This commit is contained in:
parent
e91317ca27
commit
1621901f0d
@ -1,4 +1,5 @@
|
||||
use super::ethereum_types::H256;
|
||||
use super::decode::decode_ssz_list;
|
||||
use super::{
|
||||
DecodeError,
|
||||
Decodable,
|
||||
@ -65,6 +66,16 @@ impl Decodable for H256 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Decodable for Vec<T>
|
||||
where T: Decodable
|
||||
{
|
||||
fn ssz_decode(bytes: &[u8], index: usize)
|
||||
-> Result<(Self, usize), DecodeError>
|
||||
{
|
||||
decode_ssz_list(bytes, index)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -11,8 +11,8 @@ extern crate bytes;
|
||||
extern crate ethereum_types;
|
||||
|
||||
pub mod decode;
|
||||
pub mod encode;
|
||||
|
||||
mod encode;
|
||||
mod impl_encode;
|
||||
mod impl_decode;
|
||||
|
||||
@ -29,3 +29,13 @@ pub use encode::{
|
||||
|
||||
pub const LENGTH_BYTES: usize = 4;
|
||||
pub const MAX_LIST_SIZE : usize = 1 << (4 * 8);
|
||||
|
||||
|
||||
/// Convenience function to SSZ encode an object supporting ssz::Encode.
|
||||
pub fn ssz_encode<T>(val: &T) -> Vec<u8>
|
||||
where T: Encodable
|
||||
{
|
||||
let mut ssz_stream = SszStream::new();
|
||||
ssz_stream.append(val);
|
||||
ssz_stream.drain()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user