Before renaming crates
This commit is contained in:
@@ -34,7 +34,8 @@ blake3 = "1.3.3"
|
||||
default = ["sqlite"]
|
||||
rocks = ["rocksdb", "rayon", "is_sync"]
|
||||
sqlite = ["rusqlite", "rayon", "r2d2", "tokio", "is_sync"]
|
||||
foundation = ["foundationdb", "futures", "is_async"]
|
||||
foundation = ["foundationdb", "futures", "is_async", "key_subspace"]
|
||||
is_sync = ["maybe-async/is_sync", "parking_lot", "lru-cache"]
|
||||
is_async = []
|
||||
key_subspace = []
|
||||
test_mode = []
|
||||
|
||||
@@ -10,107 +10,6 @@ pub mod main;
|
||||
pub mod read;
|
||||
pub mod write;
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &IndexKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<IndexKey<T>>() + key.len() + 1)
|
||||
.write(SUBSPACE_INDEXES)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &IndexKeyPrefix {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<IndexKeyPrefix>() + 1)
|
||||
.write(SUBSPACE_INDEXES)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &ValueKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
if self.family == 0 {
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 1)
|
||||
.write(SUBSPACE_VALUES)
|
||||
.write_leb128(self.account_id)
|
||||
.write(self.collection)
|
||||
.write_leb128(self.document_id)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
} else {
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 2)
|
||||
.write(SUBSPACE_VALUES)
|
||||
.write_leb128(self.account_id)
|
||||
.write(self.collection)
|
||||
.write_leb128(self.document_id)
|
||||
.write(u8::MAX)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BitmapKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<BitmapKey<T>>() + key.len() + 1)
|
||||
.write(SUBSPACE_BITMAPS)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.block_num)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BlobKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let hash = self.hash.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<BlobKey<T>>() + BLOB_HASH_LEN + 1)
|
||||
.write(SUBSPACE_BLOBS)
|
||||
.write(hash)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &AclKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<AclKey>() + 1)
|
||||
.write(SUBSPACE_ACLS)
|
||||
.write_leb128(self.grant_account_id)
|
||||
.write(u8::MAX)
|
||||
.write_leb128(self.to_account_id)
|
||||
.write(self.to_collection)
|
||||
.write_leb128(self.to_document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &LogKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<LogKey>() + 1)
|
||||
.write(SUBSPACE_LOGS)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.change_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FdbError> for Error {
|
||||
fn from(error: FdbError) -> Self {
|
||||
Self::InternalError(format!("FoundationDB error: {}", error.message()))
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
use crate::{
|
||||
write::key::KeySerializer, AclKey, BitmapKey, BlobKey, IndexKey, IndexKeyPrefix, LogKey,
|
||||
Serialize, ValueKey, BLOB_HASH_LEN,
|
||||
};
|
||||
|
||||
pub mod id_assign;
|
||||
pub mod main;
|
||||
pub mod pool;
|
||||
@@ -15,105 +10,6 @@ const WORDS_PER_BLOCK: u32 = 16;
|
||||
pub const BITS_PER_BLOCK: u32 = WORD_SIZE_BITS * WORDS_PER_BLOCK;
|
||||
const BITS_MASK: u32 = BITS_PER_BLOCK - 1;
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &IndexKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<IndexKey<T>>() + key.len() + 1)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &IndexKeyPrefix {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<IndexKeyPrefix>() + 1)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &ValueKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
if self.family == 0 {
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 1)
|
||||
.write_leb128(self.account_id)
|
||||
.write(self.collection)
|
||||
.write_leb128(self.document_id)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
} else {
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 2)
|
||||
.write_leb128(self.account_id)
|
||||
.write(self.collection)
|
||||
.write_leb128(self.document_id)
|
||||
.write(u8::MAX)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BitmapKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<BitmapKey<T>>() + key.len() + 1)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.block_num)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BlobKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let hash = self.hash.as_ref();
|
||||
KeySerializer::new(std::mem::size_of::<BlobKey<T>>() + BLOB_HASH_LEN + 1)
|
||||
.write(hash)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for BlobKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
(&self).serialize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &AclKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<AclKey>() + 1)
|
||||
.write_leb128(self.grant_account_id)
|
||||
.write(u8::MAX)
|
||||
.write_leb128(self.to_account_id)
|
||||
.write(self.to_collection)
|
||||
.write_leb128(self.to_document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &LogKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
KeySerializer::new(std::mem::size_of::<LogKey>() + 1)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.change_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<r2d2::Error> for crate::Error {
|
||||
fn from(err: r2d2::Error) -> Self {
|
||||
Self::InternalError(format!("Connection pool error: {}", err))
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use std::convert::TryInto;
|
||||
use utils::codec::leb128::Leb128_;
|
||||
|
||||
use crate::{BlobKey, Key, ValueKey, SUBSPACE_BLOBS};
|
||||
use crate::{
|
||||
AclKey, BitmapKey, BlobKey, IndexKey, IndexKeyPrefix, Key, LogKey, Serialize, ValueKey,
|
||||
BLOB_HASH_LEN,
|
||||
};
|
||||
|
||||
pub struct KeySerializer {
|
||||
buf: Vec<u8>,
|
||||
@@ -118,7 +121,7 @@ impl DeserializeBigEndian for &[u8] {
|
||||
|
||||
impl<T: AsRef<[u8]> + Sync + Send + 'static> Key for BlobKey<T> {
|
||||
fn subspace(&self) -> u8 {
|
||||
SUBSPACE_BLOBS
|
||||
crate::SUBSPACE_BLOBS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,3 +148,142 @@ impl ValueKey {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &IndexKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<IndexKey<T>>() + key.len() + 1)
|
||||
.write(crate::SUBSPACE_INDEXES)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<IndexKey<T>>() + key.len()) }
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &IndexKeyPrefix {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<IndexKeyPrefix>() + 1)
|
||||
.write(crate::SUBSPACE_INDEXES)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<IndexKeyPrefix>()) }
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &ValueKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let ks = {
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 2)
|
||||
.write(crate::SUBSPACE_VALUES)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<ValueKey>() + 1)
|
||||
}
|
||||
}
|
||||
.write_leb128(self.account_id)
|
||||
.write(self.collection)
|
||||
.write_leb128(self.document_id);
|
||||
|
||||
if self.family == 0 {
|
||||
ks.write(self.field).finalize()
|
||||
} else {
|
||||
ks.write(u8::MAX)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BitmapKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let key = self.key.as_ref();
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<BitmapKey<T>>() + key.len() + 1)
|
||||
.write(crate::SUBSPACE_BITMAPS)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<BitmapKey<T>>() + key.len()) }
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.family)
|
||||
.write(self.field)
|
||||
.write(key)
|
||||
.write(self.block_num)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for &BlobKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
let hash = self.hash.as_ref();
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<BlobKey<T>>() + BLOB_HASH_LEN + 1)
|
||||
.write(crate::SUBSPACE_BLOBS)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<BlobKey<T>>() + BLOB_HASH_LEN) }
|
||||
.write(hash)
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AsRef<[u8]>> Serialize for BlobKey<T> {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
(&self).serialize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &AclKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<AclKey>() + 1).write(crate::SUBSPACE_ACLS)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<AclKey>()) }
|
||||
.write_leb128(self.grant_account_id)
|
||||
.write(u8::MAX)
|
||||
.write_leb128(self.to_account_id)
|
||||
.write(self.to_collection)
|
||||
.write_leb128(self.to_document_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for &LogKey {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
#[cfg(feature = "key_subspace")]
|
||||
{
|
||||
KeySerializer::new(std::mem::size_of::<LogKey>() + 1).write(crate::SUBSPACE_LOGS)
|
||||
}
|
||||
#[cfg(not(feature = "key_subspace"))]
|
||||
{ KeySerializer::new(std::mem::size_of::<LogKey>()) }
|
||||
.write(self.account_id)
|
||||
.write(self.collection)
|
||||
.write(self.change_id)
|
||||
.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user