use bincode::{Decode, Encode};
use crate::infinitedb_core::address::{Address, RevisionId};
use crate::infinitedb_core::hyperedge::{Hyperedge, HyperedgeId};
use crate::infinitedb_core::signal::SignalSample;
use crate::infinitedb_core::address::SpaceId;
#[derive(Debug, Clone, Encode, Decode)]
pub enum SyncOperation {
Write {
address: Address,
revision: RevisionId,
data: Vec<u8>,
},
Tombstone {
address: Address,
revision: RevisionId,
},
WriteHyperedge {
space: SpaceId,
edge: Hyperedge,
revision: RevisionId,
},
DeleteHyperedge {
space: SpaceId,
edge_id: HyperedgeId,
revision: RevisionId,
},
WriteSignal {
space: SpaceId,
sample: SignalSample,
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())
}
}