diff --git a/ethers-core/src/types/bytes.rs b/ethers-core/src/types/bytes.rs index 35c0e28d..a23f0521 100644 --- a/ethers-core/src/types/bytes.rs +++ b/ethers-core/src/types/bytes.rs @@ -1,6 +1,5 @@ +use fastrlp::{Decodable, Encodable}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use thiserror::Error; - use std::{ borrow::Borrow, clone::Clone, @@ -8,6 +7,7 @@ use std::{ ops::Deref, str::FromStr, }; +use thiserror::Error; /// Wrapper type around Bytes to deserialize/serialize "0x" prefixed ethereum hex strings #[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd)] @@ -131,6 +131,21 @@ impl PartialEq for Bytes { } } +impl Encodable for Bytes { + fn length(&self) -> usize { + self.0.length() + } + fn encode(&self, out: &mut dyn bytes::BufMut) { + self.0.encode(out) + } +} + +impl Decodable for Bytes { + fn decode(buf: &mut &[u8]) -> Result { + Ok(Self(bytes::Bytes::decode(buf)?)) + } +} + #[derive(Debug, Clone, Error)] #[error("Failed to parse bytes: {0}")] pub struct ParseBytesError(String);