mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Get ride of rust messagepack (rmp)
This commit is contained in:
parent
81bf6d583d
commit
710ab2386c
9 changed files with 45 additions and 76 deletions
|
@ -3,8 +3,9 @@ use std::io::Cursor;
|
|||
use std::{fmt, error::Error};
|
||||
|
||||
use meilidb_schema::{Schema, SchemaAttr};
|
||||
use rmp_serde::decode::{Deserializer as RmpDeserializer, ReadReader};
|
||||
use rmp_serde::decode::{Error as RmpError};
|
||||
use serde_json::Error as SerdeJsonError;
|
||||
use serde_json::Deserializer as SerdeJsonDeserializer;
|
||||
use serde_json::de::IoRead as SerdeJsonIoRead;
|
||||
use serde::{de, forward_to_deserialize_any};
|
||||
|
||||
use crate::store::DocumentsFields;
|
||||
|
@ -12,8 +13,8 @@ use crate::DocumentId;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum DeserializerError {
|
||||
RmpError(RmpError),
|
||||
RkvError(rkv::StoreError),
|
||||
SerdeJson(SerdeJsonError),
|
||||
Rkv(rkv::StoreError),
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
|
@ -26,8 +27,8 @@ impl de::Error for DeserializerError {
|
|||
impl fmt::Display for DeserializerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
DeserializerError::RmpError(e) => write!(f, "rmp serde related error: {}", e),
|
||||
DeserializerError::RkvError(e) => write!(f, "rkv related error: {}", e),
|
||||
DeserializerError::SerdeJson(e) => write!(f, "serde json related error: {}", e),
|
||||
DeserializerError::Rkv(e) => write!(f, "rkv related error: {}", e),
|
||||
DeserializerError::Custom(s) => f.write_str(s),
|
||||
}
|
||||
}
|
||||
|
@ -35,15 +36,15 @@ impl fmt::Display for DeserializerError {
|
|||
|
||||
impl Error for DeserializerError {}
|
||||
|
||||
impl From<RmpError> for DeserializerError {
|
||||
fn from(error: RmpError) -> DeserializerError {
|
||||
DeserializerError::RmpError(error)
|
||||
impl From<SerdeJsonError> for DeserializerError {
|
||||
fn from(error: SerdeJsonError) -> DeserializerError {
|
||||
DeserializerError::SerdeJson(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rkv::StoreError> for DeserializerError {
|
||||
fn from(error: rkv::StoreError) -> DeserializerError {
|
||||
DeserializerError::RkvError(error)
|
||||
DeserializerError::Rkv(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +89,12 @@ where R: rkv::Readable,
|
|||
let is_displayed = self.schema.props(attr).is_displayed();
|
||||
if is_displayed && self.attributes.map_or(true, |f| f.contains(&attr)) {
|
||||
let attribute_name = self.schema.attribute_name(attr);
|
||||
Some((attribute_name, Value::new(value)))
|
||||
|
||||
let cursor = Cursor::new(value.to_owned());
|
||||
let ioread = SerdeJsonIoRead::new(cursor);
|
||||
let value = Value(SerdeJsonDeserializer::new(ioread));
|
||||
|
||||
Some((attribute_name, value))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -104,18 +110,9 @@ where R: rkv::Readable,
|
|||
}
|
||||
}
|
||||
|
||||
struct Value<A>(RmpDeserializer<ReadReader<Cursor<A>>>) where A: AsRef<[u8]>;
|
||||
struct Value(SerdeJsonDeserializer<SerdeJsonIoRead<Cursor<Vec<u8>>>>);
|
||||
|
||||
impl<A> Value<A> where A: AsRef<[u8]>
|
||||
{
|
||||
fn new(value: A) -> Value<A> {
|
||||
Value(RmpDeserializer::new(Cursor::new(value)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, A> de::IntoDeserializer<'de, RmpError> for Value<A>
|
||||
where A: AsRef<[u8]>,
|
||||
{
|
||||
impl<'de> de::IntoDeserializer<'de, SerdeJsonError> for Value {
|
||||
type Deserializer = Self;
|
||||
|
||||
fn into_deserializer(self) -> Self::Deserializer {
|
||||
|
@ -123,10 +120,8 @@ where A: AsRef<[u8]>,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'a, A> de::Deserializer<'de> for Value<A>
|
||||
where A: AsRef<[u8]>,
|
||||
{
|
||||
type Error = RmpError;
|
||||
impl<'de> de::Deserializer<'de> for Value {
|
||||
type Error = SerdeJsonError;
|
||||
|
||||
fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor<'de>
|
||||
|
|
|
@ -26,7 +26,6 @@ use std::collections::BTreeMap;
|
|||
use std::{fmt, error::Error};
|
||||
|
||||
use meilidb_schema::SchemaAttr;
|
||||
use rmp_serde::encode::Error as RmpError;
|
||||
use serde_json::Error as SerdeJsonError;
|
||||
use serde::ser;
|
||||
|
||||
|
@ -36,10 +35,9 @@ use crate::{DocumentId, ParseNumberError};
|
|||
pub enum SerializerError {
|
||||
DocumentIdNotFound,
|
||||
InvalidDocumentIdType,
|
||||
RmpError(RmpError),
|
||||
RkvError(rkv::StoreError),
|
||||
SerdeJsonError(SerdeJsonError),
|
||||
ParseNumberError(ParseNumberError),
|
||||
SerdeJson(SerdeJsonError),
|
||||
ParseNumber(ParseNumberError),
|
||||
UnserializableType { type_name: &'static str },
|
||||
UnindexableType { type_name: &'static str },
|
||||
UnrankableType { type_name: &'static str },
|
||||
|
@ -56,15 +54,14 @@ impl fmt::Display for SerializerError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SerializerError::DocumentIdNotFound => {
|
||||
write!(f, "serialized document does not have an id according to the schema")
|
||||
f.write_str("serialized document does not have an id according to the schema")
|
||||
},
|
||||
SerializerError::InvalidDocumentIdType => {
|
||||
write!(f, "document identifier can only be of type string or number")
|
||||
f.write_str("document identifier can only be of type string or number")
|
||||
},
|
||||
SerializerError::RmpError(e) => write!(f, "rmp serde related error: {}", e),
|
||||
SerializerError::RkvError(e) => write!(f, "rkv related error: {}", e),
|
||||
SerializerError::SerdeJsonError(e) => write!(f, "serde json error: {}", e),
|
||||
SerializerError::ParseNumberError(e) => {
|
||||
SerializerError::SerdeJson(e) => write!(f, "serde json error: {}", e),
|
||||
SerializerError::ParseNumber(e) => {
|
||||
write!(f, "error while trying to parse a number: {}", e)
|
||||
},
|
||||
SerializerError::UnserializableType { type_name } => {
|
||||
|
@ -89,15 +86,9 @@ impl From<String> for SerializerError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<RmpError> for SerializerError {
|
||||
fn from(error: RmpError) -> SerializerError {
|
||||
SerializerError::RmpError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SerdeJsonError> for SerializerError {
|
||||
fn from(error: SerdeJsonError) -> SerializerError {
|
||||
SerializerError::SerdeJsonError(error)
|
||||
SerializerError::SerdeJson(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +100,7 @@ impl From<rkv::StoreError> for SerializerError {
|
|||
|
||||
impl From<ParseNumberError> for SerializerError {
|
||||
fn from(error: ParseNumberError) -> SerializerError {
|
||||
SerializerError::ParseNumberError(error)
|
||||
SerializerError::ParseNumber(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ where T: ser::Serialize,
|
|||
if let Some(attribute) = schema.attribute(key) {
|
||||
let props = schema.props(attribute);
|
||||
|
||||
let serialized = rmp_serde::to_vec_named(value)?;
|
||||
let serialized = serde_json::to_vec(value)?;
|
||||
document_store.set_document_field(document_id, attribute, serialized);
|
||||
|
||||
if props.is_indexed() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue