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 serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
clone::Clone,
|
clone::Clone,
|
||||||
|
@ -8,6 +7,7 @@ use std::{
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Wrapper type around Bytes to deserialize/serialize "0x" prefixed ethereum hex strings
|
/// Wrapper type around Bytes to deserialize/serialize "0x" prefixed ethereum hex strings
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize, Ord, PartialOrd)]
|
#[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)]
|
#[derive(Debug, Clone, Error)]
|
||||||
#[error("Failed to parse bytes: {0}")]
|
#[error("Failed to parse bytes: {0}")]
|
||||||
pub struct ParseBytesError(String);
|
pub struct ParseBytesError(String);
|
||||||
|
|
Loading…
Reference in New Issue