2020-10-21 21:51:48 +08:00
|
|
|
use std::borrow::Cow;
|
2021-06-17 00:33:33 +08:00
|
|
|
|
2021-07-06 17:31:24 +08:00
|
|
|
use obkv::{KvReaderU16, KvWriterU16};
|
2020-10-21 21:51:48 +08:00
|
|
|
|
|
|
|
pub struct ObkvCodec;
|
|
|
|
|
|
|
|
impl<'a> heed::BytesDecode<'a> for ObkvCodec {
|
2021-07-06 17:31:24 +08:00
|
|
|
type DItem = KvReaderU16<'a>;
|
2020-10-21 21:51:48 +08:00
|
|
|
|
|
|
|
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
2021-07-06 17:31:24 +08:00
|
|
|
Some(KvReaderU16::new(bytes))
|
2020-10-21 21:51:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl heed::BytesEncode<'_> for ObkvCodec {
|
2021-07-06 17:31:24 +08:00
|
|
|
type EItem = KvWriterU16<Vec<u8>>;
|
2020-10-21 21:51:48 +08:00
|
|
|
|
|
|
|
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
|
|
|
|
item.clone().into_inner().map(Cow::Owned).ok()
|
|
|
|
}
|
|
|
|
}
|