mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Fix updates serialization to use serde_json instead of bincode
This commit is contained in:
parent
261c21b057
commit
1cf6afad9a
@ -1,11 +1,31 @@
|
|||||||
use zlmdb::types::{OwnedType, Serde};
|
use std::borrow::Cow;
|
||||||
use zlmdb::Result as ZResult;
|
use zlmdb::types::OwnedType;
|
||||||
|
use zlmdb::{Result as ZResult, BytesEncode, BytesDecode};
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
use crate::update::Update;
|
use crate::update::Update;
|
||||||
use super::BEU64;
|
use super::BEU64;
|
||||||
|
|
||||||
|
pub struct SerdeJson<T>(std::marker::PhantomData<T>);
|
||||||
|
|
||||||
|
impl<T> BytesEncode for SerdeJson<T> where T: Serialize {
|
||||||
|
type EItem = T;
|
||||||
|
|
||||||
|
fn bytes_encode(item: &Self::EItem) -> Option<Cow<[u8]>> {
|
||||||
|
serde_json::to_vec(item).map(Cow::Owned).ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: 'a> BytesDecode<'a> for SerdeJson<T> where T: Deserialize<'a> + Clone {
|
||||||
|
type DItem = T;
|
||||||
|
|
||||||
|
fn bytes_decode(bytes: &'a [u8]) -> Option<Self::DItem> {
|
||||||
|
serde_json::from_slice(bytes).ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Updates {
|
pub struct Updates {
|
||||||
pub(crate) updates: zlmdb::Database<OwnedType<BEU64>, Serde<Update>>,
|
pub(crate) updates: zlmdb::Database<OwnedType<BEU64>, SerdeJson<Update>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Updates {
|
impl Updates {
|
||||||
|
Loading…
Reference in New Issue
Block a user