26 #include "../algorithm.h"
27 #include "../assert.h"
51 using def_type = std::tuple< tag< ID >, Defs... >;
55 template <
typename... NewDefs >
74 template < std::endian
Endianess,
typename... Cmds >
80 static constexpr std::size_t get_id_index(
auto id )
82 return find_index<
sizeof...( Cmds ) >( [
id]< std::size_t i >() {
83 return std::tuple_element_t< i, cmds_type >::id == id;
89 static constexpr std::size_t
id_index = get_id_index( ID );
97 template <
typename... SubCmds >
101 are_same_v< typename Cmds::id_type... >,
102 "Each command of one group has to use same type of id" );
114 template <
auto id,
typename... Args >
118 std::optional< value_type >
res;
121 using cmd = std::tuple_element_t< i, cmds_type >;
122 if constexpr ( cmd::id ==
id )
123 res.emplace( cmd::make_val(
args... ) );
131 template < std::endian Endianess >
134 template <
typename... Cmds >
#define EMLABCPP_ASSERT(cond)
MIT License.
Definition: assert.h:38
Protocol library has custom type that represents message, however this is just simple overaly over st...
Definition: message.h:40
MIT License.
Definition: multiplexer.h:33
Endianess
Definition: serializer.h:70
concept convertible
This concepts limits types to types that can be declared, that is the overload of 'traits_for' is ful...
Definition: traits.h:67
Serializes values from definitions Ds to std::variant.
Definition: base.h:89
Each definition of item provided to protocol library should have specialization of 'proto_traits' str...
Definition: traits.h:44
std::variant< int64_t, float, bool, string_buffer > value_type
Definition: base.h:51
constexpr void for_each_index(NullCallable &&f)
Executes unary callable f() with template argument of type 'std::size_t', which ranges from 0 to N.
Definition: algorithm.h:466
Args const & args
Definition: min_max.h:83
T res
Definition: algorithm.h:505
Command group should be used as a collection of commands that are selected based on the ID,...
Definition: command_group.h:76
std::tuple_element_t< id_index< ID >, cmds_type > cmd_type
Definition: command_group.h:92
requires((id==Cmds::id)||...) const expr static value_type make_val(Args const &... args)
Creates value of the command group, that is variant with value of the command 'id' that will receive ...
Definition: command_group.h:115
static constexpr std::size_t max_size
Definition: command_group.h:108
static constexpr std::size_t id_index
Definition: command_group.h:89
typename cmd_type< ID >::value_type cmd_value_type
Definition: command_group.h:95
typename traits::value_type value_type
Definition: command_group.h:106
std::tuple< Cmds... > cmds_type
Definition: command_group.h:77
Command group represents a segment in the message, that may contain multiple different variants of va...
Definition: command_group.h:48
constexpr static value_type make_val(typename proto_traits< Defs >::value_type const &... args)
Creates value of the command based on the args.
Definition: command_group.h:60
decltype(ID) id_type
Definition: command_group.h:49
std::tuple< tag< ID >, typename proto_traits< Defs >::value_type... > value_type
Definition: command_group.h:50
std::tuple< tag< ID >, Defs... > def_type
Definition: command_group.h:51
More complex constructs have custom mechanics that internally produces def_type alias used by the lib...
Definition: base.h:122
Follows a set of special data types used for definition of protocol.
Definition: base.h:79