use std::future::Future;
use pilota::thrift::ThriftException;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{EntryMessage, ThriftMessage, context::ThriftContext};
pub mod default;
pub use default::DefaultMakeCodec;
pub trait Decoder: Send + Sync + 'static {
fn decode<Msg: Send + EntryMessage, Cx: ThriftContext>(
&mut self,
cx: &mut Cx,
) -> impl Future<Output = Result<Option<ThriftMessage<Msg>>, ThriftException>> + Send;
fn is_closed(&self) -> impl Future<Output = bool> + Send {
async { false }
}
#[cfg(feature = "shmipc")]
fn shmipc_helper(&self) -> ::volo::net::shmipc::ShmipcHelper {
::volo::net::shmipc::ShmipcHelper::none()
}
}
pub trait Encoder: Send + Sync + 'static {
fn encode<Req: Send + EntryMessage, Cx: ThriftContext>(
&mut self,
cx: &mut Cx,
msg: ThriftMessage<Req>,
) -> impl Future<Output = Result<(), ThriftException>> + Send;
fn is_closed(&self) -> impl Future<Output = bool> + Send {
async { false }
}
#[cfg(feature = "shmipc")]
fn shmipc_helper(&self) -> ::volo::net::shmipc::ShmipcHelper {
::volo::net::shmipc::ShmipcHelper::none()
}
}
pub trait MakeCodec<R, W>: Clone + Send + 'static
where
R: AsyncRead + Unpin + Send + Sync + 'static,
W: AsyncWrite + Unpin + Send + Sync + 'static,
{
type Encoder: Encoder;
type Decoder: Decoder;
fn make_codec(&self, reader: R, writer: W) -> (Self::Encoder, Self::Decoder);
}