mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 08:37:59 -05:00
chore: add helper serialize functions (#3015)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
//! Various serde utilities
|
||||
|
||||
mod storage_key;
|
||||
|
||||
use serde::Serializer;
|
||||
pub use storage_key::*;
|
||||
|
||||
mod jsonu256;
|
||||
use crate::H256;
|
||||
pub use jsonu256::*;
|
||||
|
||||
pub mod num;
|
||||
@@ -58,6 +61,27 @@ pub mod hex_bytes {
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialize a byte vec as a hex string _without_ 0x prefix.
|
||||
///
|
||||
/// This behaves exactly as [hex::encode]
|
||||
pub fn serialize_hex_string_no_prefix<S, T>(x: T, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
T: AsRef<[u8]>,
|
||||
{
|
||||
s.serialize_str(&hex::encode(x.as_ref()))
|
||||
}
|
||||
|
||||
/// Serialize a byte vec as a hex string _without_ 0x prefix
|
||||
pub fn serialize_h256_hex_string_no_prefix<S>(x: &H256, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let val = format!("{:?}", x);
|
||||
// skip the 0x prefix
|
||||
s.serialize_str(&val.as_str()[2..])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user