use crate::DatabaseError;
use reth_db_api::table::{Decode, Decompress, Table, TableRow};
use std::borrow::Cow;
pub(crate) fn decoder<'a, T>(
(k, v): (Cow<'a, [u8]>, Cow<'a, [u8]>),
) -> Result<TableRow<T>, DatabaseError>
where
T: Table,
T::Key: Decode,
T::Value: Decompress,
{
Ok((
match k {
Cow::Borrowed(k) => Decode::decode(k)?,
Cow::Owned(k) => Decode::decode_owned(k)?,
},
match v {
Cow::Borrowed(v) => Decompress::decompress(v)?,
Cow::Owned(v) => Decompress::decompress_owned(v)?,
},
))
}
pub(crate) fn decode_value<'a, T>(
kv: (Cow<'a, [u8]>, Cow<'a, [u8]>),
) -> Result<T::Value, DatabaseError>
where
T: Table,
{
Ok(match kv.1 {
Cow::Borrowed(v) => Decompress::decompress(v)?,
Cow::Owned(v) => Decompress::decompress_owned(v)?,
})
}
pub(crate) fn decode_one<T>(value: Cow<'_, [u8]>) -> Result<T::Value, DatabaseError>
where
T: Table,
{
Ok(match value {
Cow::Borrowed(v) => Decompress::decompress(v)?,
Cow::Owned(v) => Decompress::decompress_owned(v)?,
})
}