userver: userver/ugrpc/server/impl/call_traits.hpp Source File
Loading...
Searching...
No Matches
call_traits.hpp
1#pragma once
2
3#include <userver/ugrpc/server/rpc.hpp>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace ugrpc::server::impl {
8
9struct NoInitialRequest final {};
10
11enum class CallCategory {
12 kUnary,
13 kInputStream,
14 kOutputStream,
15 kBidirectionalStream,
16};
17
18template <typename HandlerMethod>
19struct CallTraits;
20
21template <typename ServiceBaseType, typename RequestType, typename ResponseType>
22struct CallTraits<void (ServiceBaseType::*)(UnaryCall<ResponseType>&,
23 RequestType&&)>
24 final {
25 using ServiceBase = ServiceBaseType;
26 using Request = RequestType;
27 using Response = ResponseType;
28 using RawCall = impl::RawResponseWriter<ResponseType>;
29 using InitialRequest = Request;
30 using Call = UnaryCall<Response>;
31 using ServiceMethod = void (ServiceBase::*)(Call&, Request&&);
32 static constexpr auto kCallCategory = CallCategory::kUnary;
33};
34
35template <typename ServiceBaseType, typename RequestType, typename ResponseType>
36struct CallTraits<void (ServiceBaseType::*)(
37 InputStream<RequestType, ResponseType>&)>
38 final {
39 using ServiceBase = ServiceBaseType;
40 using Request = RequestType;
41 using Response = ResponseType;
42 using RawCall = impl::RawReader<Request, Response>;
43 using InitialRequest = NoInitialRequest;
44 using Call = InputStream<Request, Response>;
45 using ServiceMethod = void (ServiceBase::*)(Call&);
46 static constexpr auto kCallCategory = CallCategory::kInputStream;
47};
48
49template <typename ServiceBaseType, typename RequestType, typename ResponseType>
50struct CallTraits<void (ServiceBaseType::*)(OutputStream<ResponseType>&,
51 RequestType&&)>
52 final {
53 using ServiceBase = ServiceBaseType;
54 using Request = RequestType;
55 using Response = ResponseType;
56 using RawCall = impl::RawWriter<Response>;
57 using InitialRequest = Request;
58 using Call = OutputStream<Response>;
59 using ServiceMethod = void (ServiceBase::*)(Call&, Request&&);
60 static constexpr auto kCallCategory = CallCategory::kOutputStream;
61};
62
63template <typename ServiceBaseType, typename RequestType, typename ResponseType>
64struct CallTraits<void (ServiceBaseType::*)(
65 BidirectionalStream<RequestType, ResponseType>&)>
66 final {
67 using ServiceBase = ServiceBaseType;
68 using Request = RequestType;
69 using Response = ResponseType;
70 using RawCall = impl::RawReaderWriter<Request, Response>;
71 using InitialRequest = NoInitialRequest;
72 using Call = BidirectionalStream<Request, Response>;
73 using ServiceMethod = void (ServiceBase::*)(Call&);
74 static constexpr auto kCallCategory = CallCategory::kBidirectionalStream;
75};
76
77} // namespace ugrpc::server::impl
78
79USERVER_NAMESPACE_END