2020-06-22 17:56:07 +02:00
|
|
|
use std::borrow::Cow;
|
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
|
|
|
|
pub struct RoaringBitmapCodec;
|
|
|
|
|
|
|
|
impl heed::BytesDecode<'_> for RoaringBitmapCodec {
|
|
|
|
type DItem = RoaringBitmap;
|
|
|
|
|
|
|
|
fn bytes_decode(bytes: &[u8]) -> Option<Self::DItem> {
|
|
|
|
RoaringBitmap::deserialize_from(bytes).ok()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl heed::BytesEncode<'_> for RoaringBitmapCodec {
|
|
|
|
type EItem = RoaringBitmap;
|
|
|
|
|
|
|
|
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
|
2020-08-29 11:21:30 +02:00
|
|
|
let mut bytes = Vec::with_capacity(item.serialized_size());
|
2020-06-22 17:56:07 +02:00
|
|
|
item.serialize_into(&mut bytes).ok()?;
|
|
|
|
Some(Cow::Owned(bytes))
|
|
|
|
}
|
|
|
|
}
|