diff --git a/ssz/src/decode/impls.rs b/ssz/src/decode/impls.rs index 9b57745..00c547f 100644 --- a/ssz/src/decode/impls.rs +++ b/ssz/src/decode/impls.rs @@ -1,6 +1,6 @@ use super::*; use crate::decode::try_from_iter::{TryCollect, TryFromIter}; -use alloy_primitives::{Address, Bytes, FixedBytes, U128, U256}; +use alloy_primitives::{Address, Bloom, Bytes, FixedBytes, U128, U256}; use core::num::NonZeroUsize; use itertools::process_results; use smallvec::SmallVec; @@ -320,6 +320,27 @@ impl Decode for FixedBytes { } } +impl Decode for Bloom { + fn is_ssz_fixed_len() -> bool { + true + } + + fn ssz_fixed_len() -> usize { + 256 + } + + fn from_ssz_bytes(bytes: &[u8]) -> Result { + let len = bytes.len(); + let expected = ::ssz_fixed_len(); + + if len != expected { + Err(DecodeError::InvalidByteLength { len, expected }) + } else { + Ok(Self::from_slice(bytes)) + } + } +} + impl Decode for U256 { fn is_ssz_fixed_len() -> bool { true diff --git a/ssz/src/encode/impls.rs b/ssz/src/encode/impls.rs index c691164..d779e64 100644 --- a/ssz/src/encode/impls.rs +++ b/ssz/src/encode/impls.rs @@ -1,5 +1,5 @@ use super::*; -use alloy_primitives::{Address, Bytes, FixedBytes, U128, U256}; +use alloy_primitives::{Address, Bloom, Bytes, FixedBytes, U128, U256}; use core::num::NonZeroUsize; use smallvec::SmallVec; use std::collections::{BTreeMap, BTreeSet}; @@ -454,6 +454,33 @@ impl Encode for FixedBytes { } } +impl Encode for Bloom { + #[inline] + fn is_ssz_fixed_len() -> bool { + true + } + + #[inline] + fn ssz_bytes_len(&self) -> usize { + 256 + } + + #[inline] + fn ssz_fixed_len() -> usize { + 256 + } + + #[inline] + fn ssz_append(&self, buf: &mut Vec) { + buf.extend_from_slice(&self.0 .0); + } + + #[inline] + fn as_ssz_bytes(&self) -> Vec { + self.0.to_vec() + } +} + impl Encode for Bytes { #[inline] fn is_ssz_fixed_len() -> bool {