Improve the Mtbl heed codec to only encode MTBL databases

This commit is contained in:
Clément Renault
2020-08-29 11:20:39 +02:00
parent 21aafd603c
commit 3fe497e129
5 changed files with 17 additions and 12 deletions

View File

@ -1,9 +1,10 @@
use std::borrow::Cow;
use std::marker::PhantomData;
use oxidized_mtbl::Reader;
pub struct MtblCodec;
pub struct MtblCodec<A>(PhantomData<A>);
impl<'a> heed::BytesDecode<'a> for MtblCodec {
impl<'a> heed::BytesDecode<'a> for MtblCodec<&'a [u8]> {
type DItem = Reader<&'a [u8]>;
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
@ -11,10 +12,10 @@ impl<'a> heed::BytesDecode<'a> for MtblCodec {
}
}
impl heed::BytesEncode<'_> for MtblCodec {
type EItem = [u8];
impl<'a, A: AsRef<[u8]> + 'a> heed::BytesEncode<'a> for MtblCodec<A> {
type EItem = Reader<A>;
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
Some(Cow::Borrowed(item))
Some(Cow::Borrowed(item.as_bytes()))
}
}