use bincode::{Decode, Encode};
use crate::infinitedb_core::address::{Address, RevisionId};
#[derive(Debug, Clone, Encode, Decode)]
pub enum SyncOperation {
Write {
address: Address,
revision: RevisionId,
data: Vec<u8>,
},
Tombstone {
address: Address,
revision: RevisionId,
},
}
#[derive(Debug, Clone, Encode, Decode)]
pub struct SyncEnvelope {
pub op_id: u64,
pub op: SyncOperation,
}
#[derive(Debug, Clone, Encode, Decode)]
pub enum SyncResult {
Ack { op_id: u64 },
Retry { op_id: u64, error: String },
ConflictStale { op_id: u64, reason: String },
}
pub trait SyncTransport: Send + Sync {
fn push_batch(&self, batch: &[SyncEnvelope]) -> Result<Vec<SyncResult>, String>;
}
pub struct NoopSyncTransport;
impl SyncTransport for NoopSyncTransport {
fn push_batch(&self, batch: &[SyncEnvelope]) -> Result<Vec<SyncResult>, String> {
Ok(batch
.iter()
.map(|item| SyncResult::Retry {
op_id: item.op_id,
error: "NoopSyncTransport does not send writes".to_string(),
})
.collect())
}
}