Skip to main content

ntex_grpc/
service.rs

1use ntex_bytes::{BytePages, ByteString, Bytes};
2
3use crate::{encoding::DecodeError, server::MethodResult, types::Message};
4
5/// Trait for service method definition
6pub trait ServiceDef {
7    const NAME: &'static str;
8
9    type Methods;
10
11    fn method_by_name(name: &str) -> Option<Self::Methods>;
12}
13
14/// Trait for service method definition
15pub trait MethodDef {
16    const NAME: &'static str;
17
18    const PATH: ByteString;
19
20    type Input: Message;
21
22    type Output: Message;
23
24    #[inline]
25    fn decode(&self, buf: &mut Bytes) -> Result<Self::Input, DecodeError> {
26        Message::read(buf)
27    }
28
29    #[inline]
30    fn encode(&self, val: Self::Output, buf: &mut BytePages) {
31        val.write(buf);
32    }
33
34    #[doc(hidden)]
35    #[inline]
36    fn server_result<T: MethodResult<Self::Output>>(&self, val: T) -> Self::Output {
37        val.into()
38    }
39}