use crate::error::EdgestoreError;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct HostId(pub String);
impl fmt::Display for HostId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for HostId {
fn from(s: String) -> Self {
HostId(s)
}
}
impl From<&str> for HostId {
fn from(s: &str) -> Self {
HostId(s.to_string())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SegmentRef {
pub segment_hash: [u8; 32],
pub segment_id: u64,
}
impl SegmentRef {
#[allow(dead_code)] pub fn hash_hex(&self) -> String {
self.segment_hash
.iter()
.map(|x| format!("{:02x}", x))
.collect::<String>()
}
}
pub trait ReplicationProtocol {
fn merkle_root(&self) -> Result<[u8; 32], EdgestoreError>;
fn list_segments(&self) -> Result<Vec<SegmentRef>, EdgestoreError>;
fn fetch_segment(&self, hash: &[u8; 32]) -> Result<Vec<u8>, EdgestoreError>;
}