pub mod manifest;
pub mod provider;
pub mod sync;
#[cfg(feature = "network")]
pub mod network;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::BinsyncError;
const MIN_CHUNK: usize = 32768;
const AVG_CHUNK: usize = 65536;
const MAX_CHUNK: usize = 131072;
type ChunkId = u64;
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct Chunk {
pub hash: ChunkId,
pub offset: u64,
pub length: u64,
}
impl PartialEq<fastcdc::Chunk> for Chunk {
fn eq(&self, other: &fastcdc::Chunk) -> bool {
self.offset == other.offset as u64 && self.length == other.length as u64
}
}
impl PartialEq<Chunk> for fastcdc::Chunk {
fn eq(&self, other: &Chunk) -> bool {
self.offset == other.offset as usize && self.length == other.length as usize
}
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct FileInfo {
pub name: String,
pub directory: String,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct FileList {
pub files: Vec<FileInfo>,
}
pub struct SyncPlan {
pub operations: Vec<(PathBuf, Vec<Operation>)>,
pub total_ops: u32,
}
impl SyncPlan {
pub fn get_fetch_size(&self) -> u64 {
let mut size: u64 = 0;
for (_, operations) in &self.operations {
for operation in operations {
if let Operation::Fetch(chunk) = operation {
size = size + chunk.length;
}
}
}
size
}
}
pub enum Operation {
Seek(i64), Copy(Chunk),
Fetch(Chunk),
}
pub trait ChunkProvider {
fn set_plan(&mut self, plan: &SyncPlan);
fn get_chunk<'a>(&'a mut self, key: &u64) -> Result<&'a [u8], BinsyncError>;
}