CppWAMP
C++11 client library for the WAMP protocol
|
Go to the documentation of this file.
7 #ifndef CPPWAMP_UNPACKER_HPP
8 #define CPPWAMP_UNPACKER_HPP
23 #include "./internal/integersequence.hpp"
31 template <
typename TSlot>
46 template <
typename TSlot,
typename... TArgs>
59 void operator()(
Event event)
const;
63 void invoke(
Event&& event, internal::IntegerSequence<S...>)
const;
78 template <
typename... TArgs,
typename TSlot>
80 unpackedEvent(TSlot&& slot);
96 template <
typename TSlot,
typename... TArgs>
109 void operator()(
Event event)
const;
113 CPPWAMP_HIDDEN
void invoke(
Event&& event,
114 internal::IntegerSequence<S...>)
const;
123 template <
typename TSlot,
typename... TArgs>
138 template <
typename... TArgs,
typename TSlot>
140 simpleEvent(TSlot&& slot);
145 template <
typename... TArgs,
typename TSlot>
161 template <
typename TSlot,
typename... TArgs>
179 internal::IntegerSequence<S...>)
const;
194 template <
typename... TArgs,
typename TSlot>
196 unpackedRpc(TSlot&& slot);
214 template <
typename TSlot,
typename TResult,
typename... TArgs>
235 internal::IntegerSequence<S...>)
const;
239 internal::IntegerSequence<S...>)
const;
249 template <
typename TSlot,
typename TResult,
typename... TArgs>
265 template <
typename TResult,
typename... TArgs,
typename TSlot>
267 simpleRpc(TSlot&& slot);
272 template <
typename TResult,
typename... TArgs,
typename TSlot>
289 struct UnpackError :
public Error
291 UnpackError() :
Error(
"wamp.error.invalid_argument") {}
302 template <
typename S,
typename... A>
304 : slot_(std::move(slot))
308 template <
typename S,
typename... A>
311 if (event.args().size() <
sizeof...(A))
313 std::ostringstream oss;
314 oss <<
"Expected " <<
sizeof...(A)
315 <<
" args, but only got " << event.args().size();
316 throw internal::UnpackError().withArgs(oss.str());
321 using Seq =
typename internal::GenIntegerSequence<
sizeof...(A)>::type;
322 invoke(std::move(event), Seq());
326 template <
typename S,
typename... A>
327 template <
int ...Seq>
329 internal::IntegerSequence<Seq...>)
const
331 std::tuple<ValueTypeOf<A>...> args;
335 event.convertToTuple(args);
337 catch (
const error::Conversion& e)
339 throw internal::UnpackError().withArgs(e.what());
342 slot_(std::move(event), std::get<Seq>(std::move(args))...);
346 template <
typename... TArgs,
typename TSlot>
350 std::forward<TSlot>(slot));
359 template <
typename S,
typename... A>
361 : slot_(std::move(slot))
365 template <
typename S,
typename... A>
368 if (event.args().size() <
sizeof...(A))
370 std::ostringstream oss;
371 oss <<
"Expected " <<
sizeof...(A)
372 <<
" args, but only got " << event.args().size();
373 throw internal::UnpackError().withArgs(oss.str());
378 using Seq =
typename internal::GenIntegerSequence<
sizeof...(A)>::type;
379 invoke(std::move(event), Seq());
383 template <
typename S,
typename... A>
384 template <
int ...Seq>
386 internal::IntegerSequence<Seq...>)
const
388 std::tuple<ValueTypeOf<A>...> args;
392 event.convertToTuple(args);
394 catch (
const error::Conversion& e)
396 throw internal::UnpackError().withArgs(e.what());
399 slot_(std::get<Seq>(std::move(args))...);
403 template <
typename... TArgs,
typename TSlot>
407 std::forward<TSlot>(slot));
411 template <
typename... TArgs,
typename TSlot>
415 std::forward<TSlot>(slot));
424 template <
typename S,
typename... A>
426 : slot_(std::move(slot))
430 template <
typename S,
typename... A>
433 if (inv.args().size() <
sizeof...(A))
435 std::ostringstream oss;
436 oss <<
"Expected " <<
sizeof...(A)
437 <<
" args, but only got " << inv.args().size();
438 throw internal::UnpackError().withArgs(oss.str());
443 using Seq =
typename internal::GenIntegerSequence<
sizeof...(A)>::type;
444 return invoke(std::move(inv), Seq());
448 template <
typename S,
typename... A>
449 template <
int ...Seq>
452 internal::IntegerSequence<Seq...>)
const
454 std::tuple<ValueTypeOf<A>...> args;
458 inv.convertToTuple(args);
460 catch (
const error::Conversion& e)
462 throw internal::UnpackError().withArgs(e.what());
465 return slot_(std::move(inv), std::get<Seq>(std::move(args))...);
469 template <
typename... TArgs,
typename TSlot>
473 std::forward<TSlot>(slot) );
482 template <
typename S,
typename R,
typename... A>
484 : slot_(std::move(slot))
488 template <
typename S,
typename R,
typename... A>
491 if (inv.args().size() <
sizeof...(A))
493 std::ostringstream oss;
494 oss <<
"Expected " <<
sizeof...(A)
495 <<
" args, but only got " << inv.args().size();
496 throw internal::UnpackError().withArgs(oss.str());
501 using Seq =
typename internal::GenIntegerSequence<
sizeof...(A)>::type;
503 return invoke(IsVoidResult{}, std::move(inv), Seq());
507 template <
typename S,
typename R,
typename... A>
508 template <
int ...Seq>
512 std::tuple<ValueTypeOf<A>...> args;
516 inv.convertToTuple(args);
518 catch (
const error::Conversion& e)
520 throw internal::UnpackError().withArgs(e.what());
523 slot_(std::get<Seq>(std::move(args))...);
528 template <
typename S,
typename R,
typename... A>
529 template <
int ...Seq>
530 Outcome SimpleInvocationUnpacker<S,R,A...>::invoke(
531 FalseType, Invocation&& inv, internal::IntegerSequence<Seq...>)
const
533 std::tuple<ValueTypeOf<A>...> args;
537 inv.convertToTuple(args);
539 catch (
const error::Conversion& e)
541 throw internal::UnpackError().withArgs(e.what());
544 ResultType result = slot_(std::get<Seq>(std::move(args))...);
545 return Result().withArgs(std::move(result));
549 template <
typename TResult,
typename... TArgs,
typename TSlot>
550 SimpleInvocationUnpacker<DecayedSlot<TSlot>, TResult, TArgs...>
551 simpleRpc(TSlot&& slot)
554 std::forward<TSlot>(slot) );
558 template <
typename TResult,
typename... TArgs,
typename TSlot>
563 std::forward<TSlot>(slot) );
568 #endif // CPPWAMP_UNPACKER_HPP
Outcome operator()(Invocation inv) const
Dispatches the stored call slot.
Definition: unpacker.hpp:489
Wrapper around an event slot which automatically unpacks positional payload arguments.
Definition: unpacker.hpp:47
TSlot Slot
The function type to be wrapped.
Definition: unpacker.hpp:219
BoolConstant< false > FalseType
Equivalent to std::false_type provided in C++17.
Definition: traits.hpp:122
TSlot Slot
The function type to be wrapped.
Definition: unpacker.hpp:51
SimpleInvocationUnpacker< DecayedSlot< TSlot >, TResult, TArgs... > basicRpc(TSlot &&slot)
Definition: unpacker.hpp:560
InvocationUnpacker(Slot slot)
Constructor taking a callable target.
Definition: unpacker.hpp:425
TSlot Slot
The function type to be wrapped.
Definition: unpacker.hpp:166
BoolConstant< true > TrueType
Equivalent to std::true_type provided in C++17.
Definition: traits.hpp:117
SimpleEventUnpacker< DecayedSlot< TSlot >, TArgs... > basicEvent(TSlot &&slot)
Definition: unpacker.hpp:412
Defines macros related to exporting/importing APIs.
void operator()(Event event) const
Dispatches the stored event slot.
Definition: unpacker.hpp:309
Provides the reason URI, options, and payload arguments contained within WAMP ERROR messages.
Definition: peerdata.hpp:292
Wrapper around a call slot which automatically unpacks positional payload arguments.
Definition: unpacker.hpp:215
TSlot Slot
The function type to be wrapped.
Definition: unpacker.hpp:101
Contains declarations for data structures exchanged between WAMP peers.
Definition: anyhandler.hpp:36
SimpleInvocationUnpacker(Slot slot)
Constructor taking a callable target.
Definition: unpacker.hpp:483
TResult ResultType
The static result type returned by the slot.
Definition: unpacker.hpp:222
Wrapper around a call slot which automatically unpacks positional payload arguments.
Definition: unpacker.hpp:162
SimpleEventUnpacker(Slot slot)
Constructor taking a callable target.
Definition: unpacker.hpp:360
Contains the outcome of an RPC invocation.
Definition: peerdata.hpp:709
typename std::decay< TSlot >::type DecayedSlot
Metafunction that removes const/reference decorations off a slot type.
Definition: unpacker.hpp:32
Outcome operator()(Invocation inv) const
Dispatches the stored call slot.
Definition: unpacker.hpp:431
EventUnpacker(Slot slot)
Constructor taking a callable target.
Definition: unpacker.hpp:303
Contains the declaration of Variant and other closely related types/functions.
Contains general-purpose type traits.
void operator()(Event event) const
Dispatches the stored event slot.
Definition: unpacker.hpp:366
Contains payload arguments and other options within WAMP INVOCATION messages.
Definition: peerdata.hpp:799
Provides the subscription/publication ids, options, and payload contained within WAMP EVENT messages.
Definition: peerdata.hpp:427
Wrapper around an event slot which automatically unpacks positional payload arguments.
Definition: unpacker.hpp:97
std::integral_constant< bool, B > BoolConstant
Equivalent to std::bool_constant provided in C++17.
Definition: traits.hpp:112