fix: Write and Read DocumentKeyAttr in big endian

This commit is contained in:
Clément Renault 2019-01-02 17:52:18 +01:00
parent 95dc6fe904
commit c05fab783a
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -2,7 +2,7 @@ use std::io::{Cursor, Read, Write};
use std::mem::size_of; use std::mem::size_of;
use std::fmt; use std::fmt;
use byteorder::{NativeEndian, WriteBytesExt, ReadBytesExt}; use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
use crate::database::schema::SchemaAttr; use crate::database::schema::SchemaAttr;
use crate::DocumentId; use crate::DocumentId;
@ -19,7 +19,7 @@ impl DocumentKey {
let mut wtr = Cursor::new(&mut buffer[..]); let mut wtr = Cursor::new(&mut buffer[..]);
wtr.write_all(b"doc-").unwrap(); wtr.write_all(b"doc-").unwrap();
wtr.write_u64::<NativeEndian>(id.0).unwrap(); wtr.write_u64::<BigEndian>(id.0).unwrap();
DocumentKey(buffer) DocumentKey(buffer)
} }
@ -43,7 +43,7 @@ impl DocumentKey {
} }
pub fn document_id(&self) -> DocumentId { 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) DocumentId(id)
} }
} }
@ -73,7 +73,7 @@ impl DocumentKeyAttr {
let mut wtr = Cursor::new(&mut buffer[..]); let mut wtr = Cursor::new(&mut buffer[..]);
wtr.write_all(&raw_key).unwrap(); wtr.write_all(&raw_key).unwrap();
wtr.write_all(b"-").unwrap(); wtr.write_all(b"-").unwrap();
wtr.write_u16::<NativeEndian>(attr.0).unwrap(); wtr.write_u16::<BigEndian>(attr.0).unwrap();
DocumentKeyAttr(buffer) DocumentKeyAttr(buffer)
} }
@ -97,13 +97,13 @@ impl DocumentKeyAttr {
} }
pub fn document_id(&self) -> DocumentId { 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) DocumentId(id)
} }
pub fn attribute(&self) -> SchemaAttr { pub fn attribute(&self) -> SchemaAttr {
let offset = 4 + size_of::<u64>() + 1; 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) SchemaAttr::new(value)
} }