reth_primitives_traits/
storage.rsuse alloy_primitives::{B256, U256};
use reth_codecs::{add_arbitrary_tests, Compact};
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(compact)]
pub struct StorageEntry {
pub key: B256,
pub value: U256,
}
impl StorageEntry {
pub const fn new(key: B256, value: U256) -> Self {
Self { key, value }
}
}
impl From<(B256, U256)> for StorageEntry {
fn from((key, value): (B256, U256)) -> Self {
Self { key, value }
}
}
impl Compact for StorageEntry {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
buf.put_slice(&self.key[..]);
self.value.to_compact(buf) + 32
}
fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
let key = B256::from_slice(&buf[..32]);
let (value, out) = U256::from_compact(&buf[32..], len - 32);
(Self { key, value }, out)
}
}