use ntex_bytes::{BytePages, ByteString, Bytes};
use crate::{encoding::DecodeError, server::MethodResult, types::Message};
pub trait ServiceDef {
const NAME: &'static str;
type Methods;
fn method_by_name(name: &str) -> Option<Self::Methods>;
}
pub trait MethodDef {
const NAME: &'static str;
const PATH: ByteString;
type Input: Message;
type Output: Message;
#[inline]
fn decode(&self, buf: &mut Bytes) -> Result<Self::Input, DecodeError> {
Message::read(buf)
}
#[inline]
fn encode(&self, val: Self::Output, buf: &mut BytePages) {
val.write(buf);
}
#[doc(hidden)]
#[inline]
fn server_result<T: MethodResult<Self::Output>>(&self, val: T) -> Self::Output {
val.into()
}
}