use std::path::Path;
use anyhow::{bail, Result};
use crate::jsonrpc::types::{JsonRpcNotification, JsonRpcRequest, JsonRpcResponse};
pub struct JsonRpcTransport {
_private: (),
}
pub struct JsonRpcSender {
_private: (),
}
pub struct JsonRpcReceiver {
_private: (),
}
pub struct JsonRpcServer {
_private: (),
}
#[derive(Debug, Clone, Copy)]
pub enum TimeoutPolicy {
Default,
Persistent,
Indefinite,
Deadline(std::time::Instant),
}
#[derive(Debug)]
pub enum IncomingMessage {
Request(crate::jsonrpc::types::JsonRpcRequest),
Notification(crate::jsonrpc::types::JsonRpcNotification),
Response(crate::jsonrpc::types::JsonRpcResponse),
}
fn platform_error() -> anyhow::Error {
anyhow::anyhow!(
"Unix-domain-socket JSON-RPC transport is not available on this platform \
(use the WebSocket transport instead)"
)
}
impl JsonRpcTransport {
pub async fn connect(_socket_path: &Path) -> Result<Self> {
bail!(platform_error());
}
pub fn split(self) -> (JsonRpcSender, JsonRpcReceiver) {
(
JsonRpcSender { _private: () },
JsonRpcReceiver { _private: () },
)
}
pub async fn send(
&mut self,
_request: &JsonRpcRequest,
_policy: TimeoutPolicy,
) -> Result<crate::jsonrpc::types::JsonRpcResponse> {
bail!(platform_error());
}
pub async fn send_notification(&mut self, _notification: &JsonRpcNotification) -> Result<()> {
bail!(platform_error());
}
pub async fn send_response(&mut self, _response: &JsonRpcResponse) -> Result<()> {
bail!(platform_error());
}
pub async fn send_raw(&mut self, _text: &str) -> Result<()> {
bail!(platform_error());
}
pub async fn receive(&mut self) -> Result<Option<IncomingMessage>> {
Ok(None)
}
}
impl JsonRpcSender {
pub async fn send_response(&mut self, _response: &JsonRpcResponse) -> Result<()> {
bail!(platform_error());
}
pub async fn send_notification(&mut self, _notification: &JsonRpcNotification) -> Result<()> {
bail!(platform_error());
}
pub async fn send_request(&mut self, _request: &JsonRpcRequest) -> Result<()> {
bail!(platform_error());
}
}
impl JsonRpcServer {
pub async fn bind(_socket_path: &Path) -> Result<Self> {
bail!(platform_error());
}
pub async fn accept(&self) -> Result<JsonRpcTransport> {
bail!(platform_error());
}
}