27 #include "../protocol/handler.h"
28 #include "../protocol/streams.h"
29 #include "../static_function.h"
51 std::variant< reactor_error, protocol::error_record, reply_error >
er;
54 template <
typename T >
57 template <
typename... Calls >
58 struct traits< std::tuple< Calls... > >
60 template <
typename Call >
63 static constexpr
auto id = Call::id;
68 template <
typename Call >
71 static constexpr
auto id = Call::id;
73 static_assert( !std::is_void_v< typename Call::reply > );
96 template <
typename Wrapper >
99 template <
typename CallDefs >
115 template <
typename Handler >
122 [&]< std::size_t i >() {
123 auto val = h(
tag< i >{}, *std::get_if< i >( &req_var ) );
135 template <
typename CallDefs >
138 return find_if_index< std::tuple_size_v< CallDefs > >( [id]< std::size_t i >() {
139 return std::tuple_element_t< i, CallDefs >::id == id;
143 template <
typename Wrapper >
162 static constexpr std::size_t
call_index = get_call_index< call_defs >( ID );
167 template <
auto ID,
typename... Args,
typename MsgCallback >
168 static std::variant< typename call_type< ID >::reply,
error >
171 auto req_msg = make_call_msg< ID >(
args... );
172 auto reply_msg = cb( req_msg );
174 return on_reply_msg< ID >( reply_msg );
177 template <
auto ID,
typename... Args >
183 request_type{ std::in_place_index< call_index< ID > >, req } );
188 static std::variant< typename call_type< ID >::reply,
error >
192 if (
auto* err = std::get_if< protocol::error_record >( &tmp ) )
193 return error{ *err };
195 auto const& var = *std::get_if< 0 >( &tmp );
196 auto* err_ptr = std::get_if< reactor_error >( &var );
197 if ( err_ptr !=
nullptr )
198 return error{ *err_ptr };
200 auto& reply_var = std::get< 0 >( var );
201 auto* ptr = std::get_if< call_index< ID > >( &reply_var );
202 if ( ptr ==
nullptr ) {
204 .
expected_index = call_index< ID >, .index = reply_var.index() } };
210 template < auto ID, auto Method >
213 static constexpr
auto id = ID;
217 static constexpr
bool void_returning = std::is_void_v< typename sig::return_type >;
221 std::conditional_t< void_returning, void_return_type, typename sig::return_type >;
226 ( obj.*Method )(
args... );
229 return ( obj.*Method )(
args... );
234 template <
typename Class,
typename... Bindings >
252 template < std::
size_t I,
typename Request >
255 using call_type = std::tuple_element_t< I, bindings_tuple >;
258 [&](
auto const&...
args ) ->
typename call_type::reply {
259 return call_type::handle( obj_,
args... );
268 template < auto ID,
typename Signature, std::
size_t CallableSize = 32 >
271 static constexpr
auto id = ID;
275 static constexpr
bool void_returning = std::is_void_v< typename sig::return_type >;
279 std::conditional_t< void_returning, void_return_type, typename sig::return_type >;
282 template <
typename... Bindings >
285 using def_type = std::tuple< Bindings... >;
286 using callbacks = std::tuple<
typename Bindings::sfunction... >;
292 static constexpr std::size_t call_index = get_call_index< def_type >( ID );
295 reply_message_type
on_message( request_message_type
const& msg )
300 template < auto ID,
typename Callable >
303 static constexpr std::size_t i = call_index< ID >;
305 std::get< i >( cbs_ ) = cb;
308 template < std::
size_t I,
typename Request >
311 using call_type = std::tuple_element_t< I, def_type >;
314 [&](
auto const&...
args ) ->
typename call_type::reply {
315 if constexpr ( call_type::void_returning ) {
316 std::get< I >( cbs_ )(
args... );
319 return std::get< I >( cbs_ )(
args... );
Protocol library has custom type that represents message, however this is just simple overaly over st...
Definition: message.h:40
reply_message_type on_message(request_message_type const &msg)
Definition: rpc.h:295
void bind(Callable cb)
Definition: rpc.h:301
auto operator()(tag< I >, Request const &req)
Definition: rpc.h:309
reply_message_type on_message(request_message_type const &msg)
Definition: rpc.h:247
bindings_tuple call_defs
Definition: rpc.h:239
std::tuple< Bindings... > bindings_tuple
Definition: rpc.h:238
typename reactor_type::request_message_type request_message_type
Definition: rpc.h:241
class_wrapper(Class &obj)
Definition: rpc.h:244
auto operator()(tag< I >, Request const &req)
Definition: rpc.h:253
typename reactor_type::reply_message_type reply_message_type
Definition: rpc.h:242
typename traits_type::reply_message_type reply_message_type
Definition: rpc.h:156
static std::variant< typename call_type< ID >::reply, error > call(MsgCallback &&cb, Args const &... args)
Definition: rpc.h:169
static std::variant< typename call_type< ID >::reply, error > on_reply_msg(auto const &reply_msg)
Definition: rpc.h:189
typename traits_type::call_defs call_defs
Definition: rpc.h:149
std::tuple_element_t< call_index< ID >, call_defs > call_type
Definition: rpc.h:165
typename traits_type::reply_type reply_type
Definition: rpc.h:152
typename traits_type::request_type request_type
Definition: rpc.h:151
typename traits_type::request_group request_group
Definition: rpc.h:153
static constexpr std::size_t call_index
Definition: rpc.h:162
typename traits_type::reply_variant reply_variant
Definition: rpc.h:150
typename traits_type::outter_reply_group outter_reply_group
Definition: rpc.h:154
static auto make_call_msg(Args const &... args)
Definition: rpc.h:178
typename traits_type::request_message_type request_message_type
Definition: rpc.h:155
typename traits_type::request_group request_group
Definition: rpc.h:106
typename traits_type::outter_reply_group outter_reply_group
Definition: rpc.h:108
static reply_message_type on_message(request_message_type const &msg, Handler &&h)
Definition: rpc.h:116
typename traits_type::reply_variant reply_variant
Definition: rpc.h:104
typename traits_type::request_type request_type
Definition: rpc.h:105
typename traits_type::reply_message_type reply_message_type
Definition: rpc.h:110
typename traits_type::reply_type reply_type
Definition: rpc.h:107
typename traits_type::request_message_type request_message_type
Definition: rpc.h:109
decltype(traits_for_impl< D >()) traits_for
Definition: traits.h:59
MIT License.
Definition: rpc.h:32
static constexpr std::size_t get_call_index(auto id)
Definition: rpc.h:136
std::variant< reply_group, reactor_error > outter_reply_group
Definition: rpc.h:86
protocol::traits_for< request_type > request_traits
Definition: rpc.h:89
std::size_t index
Definition: rpc.h:46
protocol::traits_for< outter_reply_group > reply_traits
Definition: rpc.h:90
typename protocol::traits_for< request_group >::value_type request_type
Definition: rpc.h:83
std::variant< reactor_error, protocol::error_record, reply_error > er
Definition: rpc.h:51
std::size_t expected_index
Definition: rpc.h:45
typename protocol::traits_for< reply_group >::value_type reply_variant
Definition: rpc.h:84
typename protocol::traits_for< outter_reply_group >::value_type reply_type
Definition: rpc.h:87
protocol::error_record record
Definition: rpc.h:40
std::tuple< Calls... > call_defs
Definition: rpc.h:78
decltype(auto) visit_index(Visitor &&vis, Variant const &var)
Definition: visit.h:35
decltype(auto) match(Variant &&var, Callables &&... cals)
Definition: match.h:55
Args const & args
Definition: min_max.h:83
Definition: static_function.h:109
More complex constructs have custom mechanics that internally produces def_type alias used by the lib...
Definition: base.h:122
handler< T > should be used to execute actual serialization and deserealization of protocol definitio...
Definition: handler.h:39
static std::variant< value_type, error_record > extract(view< std::byte const * > const &msg)
Definition: handler.h:57
static message_type serialize(value_type const &val)
Definition: handler.h:45
typename sig::args_type request
Definition: rpc.h:277
static constexpr bool void_returning
Definition: rpc.h:275
std::conditional_t< void_returning, void_return_type, typename sig::return_type > reply
Definition: rpc.h:279
std::conditional_t< void_returning, void_return_type, typename sig::return_type > reply
Definition: rpc.h:221
static constexpr reply handle(auto &obj, auto const &... args)
Definition: rpc.h:223
static constexpr bool void_returning
Definition: rpc.h:217
typename sig::args_type request
Definition: rpc.h:219
typename Call::reply def_type
Definition: rpc.h:75
typename Call::request def_type
Definition: rpc.h:65