2018-08-09 03:56:58 +00:00
|
|
|
/*
|
2018-09-10 05:50:35 +00:00
|
|
|
* This is a WIP of implementing an alternative
|
2018-08-09 03:56:58 +00:00
|
|
|
* serialization strategy. It attempts to follow Vitalik's
|
2018-09-10 05:50:35 +00:00
|
|
|
* "simpleserialize" format here:
|
|
|
|
* https://github.com/ethereum/beacon_chain/blob/master/beacon_chain/utils/simpleserialize.py
|
2018-08-09 03:56:58 +00:00
|
|
|
*
|
|
|
|
* This implementation is not final and would almost certainly
|
|
|
|
* have issues.
|
|
|
|
*/
|
|
|
|
extern crate bytes;
|
|
|
|
extern crate ethereum_types;
|
|
|
|
|
2018-09-19 04:48:42 +00:00
|
|
|
pub mod decode;
|
2018-10-16 02:44:26 +00:00
|
|
|
pub mod encode;
|
2018-12-04 20:37:12 +00:00
|
|
|
pub mod tree_hash;
|
2018-09-19 04:48:42 +00:00
|
|
|
|
2018-09-12 07:57:07 +00:00
|
|
|
mod impl_decode;
|
2018-11-04 14:35:00 +00:00
|
|
|
mod impl_encode;
|
2018-12-04 20:37:12 +00:00
|
|
|
mod impl_tree_hash;
|
2018-09-11 10:17:54 +00:00
|
|
|
|
2018-12-19 15:07:01 +00:00
|
|
|
pub use crate::decode::{decode_ssz, decode_ssz_list, Decodable, DecodeError};
|
|
|
|
pub use crate::encode::{Encodable, SszStream};
|
2019-01-24 03:23:51 +00:00
|
|
|
pub use crate::tree_hash::{merkle_hash, TreeHash};
|
2018-08-09 03:56:58 +00:00
|
|
|
|
2018-09-18 08:47:25 +00:00
|
|
|
pub const LENGTH_BYTES: usize = 4;
|
2018-11-04 14:35:00 +00:00
|
|
|
pub const MAX_LIST_SIZE: usize = 1 << (4 * 8);
|
2018-10-16 02:44:26 +00:00
|
|
|
|
|
|
|
/// Convenience function to SSZ encode an object supporting ssz::Encode.
|
|
|
|
pub fn ssz_encode<T>(val: &T) -> Vec<u8>
|
2018-11-04 14:35:00 +00:00
|
|
|
where
|
|
|
|
T: Encodable,
|
2018-10-16 02:44:26 +00:00
|
|
|
{
|
|
|
|
let mut ssz_stream = SszStream::new();
|
|
|
|
ssz_stream.append(val);
|
|
|
|
ssz_stream.drain()
|
|
|
|
}
|