zoe_wire_protocol/
blob.rs

1use crate::BlobId;
2use serde::{Deserialize, Serialize};
3
4/// Blob store service for file upload/download operations
5#[tarpc::service]
6pub trait BlobService {
7    /// Check if the blob store is healthy
8    async fn health_check() -> BlobResult<BlobHealth>;
9
10    /// Upload a blob and return its hash
11    async fn upload(data: Vec<u8>) -> BlobResult<BlobId>;
12
13    /// Download a blob by its hash
14    async fn download(hash: BlobId) -> BlobResult<Option<Vec<u8>>>;
15
16    /// Get information about a blob
17    async fn get_info(hash: BlobId) -> BlobResult<Option<BlobInfo>>;
18
19    // Bulk operations for sync
20    /// Check which blobs the server already has stored.
21    /// Returns a vec of `bool` in the same order as the input, where:
22    /// - `true` means the server has the blob stored
23    /// - `false` means the server doesn't have this blob yet
24    async fn check_blobs(hashes: Vec<BlobId>) -> BlobResult<Vec<bool>>;
25}
26
27/// Result type for blob operations
28pub type BlobResult<T> = Result<T, BlobError>;
29
30/// Health status of the blob store
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32pub struct BlobHealth {
33    pub status: String,
34    pub total_blobs: u64,
35    pub total_size_bytes: u64,
36}
37
38/// Information about a stored blob
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct BlobInfo {
41    pub hash: BlobId,
42    pub size_bytes: u64,
43    pub created_at: String,
44}
45
46/// Error types for blob operations
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, thiserror::Error)]
48pub enum BlobError {
49    #[error("Blob not found: {hash}")]
50    NotFound { hash: BlobId },
51
52    #[error("Invalid blob hash: {hash}")]
53    InvalidHash { hash: BlobId },
54
55    #[error("Storage error: {message}")]
56    StorageError { message: String },
57
58    #[error("Serialization error: {message}")]
59    SerializationError { message: String },
60
61    #[error("IO error: {message}")]
62    IoError { message: String },
63
64    #[error("Internal server error: {message}")]
65    InternalError { message: String },
66}