#[derive(Debug, Clone)]
pub struct TransportError {
pub code: String,
pub message: String,
}
impl TransportError {
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
TransportError {
code: code.into(),
message: message.into(),
}
}
}
#[derive(Debug, Clone)]
pub struct SegmentRequest {
pub segment_id: String,
pub table: String,
pub requested_scopes_json: String,
}
#[derive(Debug, Clone)]
pub enum BlobDownload {
Bytes(Vec<u8>),
Url {
url: String,
url_expires_at_ms: Option<i64>,
},
}
#[derive(Debug, Clone)]
pub enum BlobUploadGrant {
Url {
url: String,
url_expires_at_ms: Option<i64>,
},
Present,
None,
}
pub trait Transport {
fn sync(&mut self, request: &[u8]) -> Result<Vec<u8>, TransportError>;
fn realtime_sync(&mut self, request: &[u8]) -> Result<Vec<u8>, TransportError>;
fn download_segment(&mut self, request: &SegmentRequest) -> Result<Vec<u8>, TransportError>;
fn supports_url_fetch(&self) -> bool {
false
}
fn fetch_url(&mut self, url: &str) -> Result<Vec<u8>, TransportError> {
let _ = url;
Err(TransportError::new(
"sync.invalid_request",
"this transport has no direct URL fetch (§5.4)",
))
}
fn blob_upload(
&mut self,
blob_id: &str,
bytes: &[u8],
media_type: Option<&str>,
) -> Result<(), TransportError> {
let _ = (blob_id, bytes, media_type);
Err(TransportError::new(
"sync.invalid_request",
"this transport has no blob upload (§5.9)",
))
}
fn blob_download(&mut self, blob_id: &str) -> Result<BlobDownload, TransportError> {
let _ = blob_id;
Err(TransportError::new(
"blob.not_found",
"this transport has no blob download (§5.9)",
))
}
fn fetch_blob_url(&mut self, url: &str) -> Result<Vec<u8>, TransportError> {
let _ = url;
Err(TransportError::new(
"sync.invalid_request",
"this transport has no blob url fetch (§5.9.5)",
))
}
fn blob_upload_grant(
&mut self,
blob_id: &str,
byte_length: u64,
media_type: Option<&str>,
) -> Result<BlobUploadGrant, TransportError> {
let _ = (blob_id, byte_length, media_type);
Ok(BlobUploadGrant::None)
}
fn blob_put_url(
&mut self,
url: &str,
bytes: &[u8],
media_type: Option<&str>,
) -> Result<(), TransportError> {
let _ = (url, bytes, media_type);
Err(TransportError::new(
"sync.invalid_request",
"this transport has no blob put url (§5.9.3)",
))
}
fn realtime_connect(&mut self) -> Result<(), TransportError>;
fn realtime_send(&mut self, text: &str) -> Result<(), TransportError>;
fn realtime_close(&mut self) -> Result<(), TransportError>;
}