Implement fastrlp traits for Bytes (#1443)
* implement fastrlp traits for Bytes * cargo fmt * bump fastrlp to 0.1.2
This commit is contained in:
parent
c077a633c1
commit
b232afaabc
|
@ -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<bytes::Bytes> 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<Self, fastrlp::DecodeError> {
|
||||
Ok(Self(bytes::Bytes::decode(buf)?))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Error)]
|
||||
#[error("Failed to parse bytes: {0}")]
|
||||
pub struct ParseBytesError(String);
|
||||
|
|
Loading…
Reference in New Issue