mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
fix: Write and Read DocumentKeyAttr in big endian
This commit is contained in:
parent
95dc6fe904
commit
c05fab783a
@ -2,7 +2,7 @@ use std::io::{Cursor, Read, Write};
|
||||
use std::mem::size_of;
|
||||
use std::fmt;
|
||||
|
||||
use byteorder::{NativeEndian, WriteBytesExt, ReadBytesExt};
|
||||
use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
|
||||
|
||||
use crate::database::schema::SchemaAttr;
|
||||
use crate::DocumentId;
|
||||
@ -19,7 +19,7 @@ impl DocumentKey {
|
||||
|
||||
let mut wtr = Cursor::new(&mut buffer[..]);
|
||||
wtr.write_all(b"doc-").unwrap();
|
||||
wtr.write_u64::<NativeEndian>(id.0).unwrap();
|
||||
wtr.write_u64::<BigEndian>(id.0).unwrap();
|
||||
|
||||
DocumentKey(buffer)
|
||||
}
|
||||
@ -43,7 +43,7 @@ impl DocumentKey {
|
||||
}
|
||||
|
||||
pub fn document_id(&self) -> DocumentId {
|
||||
let id = (&self.0[4..]).read_u64::<NativeEndian>().unwrap();
|
||||
let id = (&self.0[4..]).read_u64::<BigEndian>().unwrap();
|
||||
DocumentId(id)
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ impl DocumentKeyAttr {
|
||||
let mut wtr = Cursor::new(&mut buffer[..]);
|
||||
wtr.write_all(&raw_key).unwrap();
|
||||
wtr.write_all(b"-").unwrap();
|
||||
wtr.write_u16::<NativeEndian>(attr.0).unwrap();
|
||||
wtr.write_u16::<BigEndian>(attr.0).unwrap();
|
||||
|
||||
DocumentKeyAttr(buffer)
|
||||
}
|
||||
@ -97,13 +97,13 @@ impl DocumentKeyAttr {
|
||||
}
|
||||
|
||||
pub fn document_id(&self) -> DocumentId {
|
||||
let id = (&self.0[4..]).read_u64::<NativeEndian>().unwrap();
|
||||
let id = (&self.0[4..]).read_u64::<BigEndian>().unwrap();
|
||||
DocumentId(id)
|
||||
}
|
||||
|
||||
pub fn attribute(&self) -> SchemaAttr {
|
||||
let offset = 4 + size_of::<u64>() + 1;
|
||||
let value = (&self.0[offset..]).read_u16::<NativeEndian>().unwrap();
|
||||
let value = (&self.0[offset..]).read_u16::<BigEndian>().unwrap();
|
||||
SchemaAttr::new(value)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user