26 #include "../outcome.h"
27 #include "../protocol/endpoint.h"
28 #include "../protocol/handler.h"
29 #include "../protocol/tuple.h"
30 #include "../static_vector.h"
39 template < std::
size_t N >
42 template < std::
size_t N >
45 template < std::
size_t N >
48 template < std::
size_t N >
64 std::span< std::byte const >
data,
65 std::span< std::byte > target )
77 template < std::
size_t N >
84 template <
typename BinaryCallable >
89 return outcome::ERROR;
96 template <
typename T >
98 { s.get_channel() } -> std::convertible_to< channel_type >;
99 { s.on_msg(
data ) } -> std::convertible_to< outcome >;
102 template <
slot... Slotted >
108 auto f = [&]<
typename T >( T& item ) {
109 if ( chann != item.get_channel() )
114 if ( !(
f( slotted ) || ... ||
false ) )
115 res = outcome::ERROR;
119 template <
typename Packet >
128 template < std::
size_t N >
134 template < std::
size_t N >
140 template <
typename Container >
143 ep.
insert( std::forward< Container >(
data ) );
146 std::variant< std::size_t, std::tuple< channel_type, payload_message >,
error_record >
152 template <
typename NextCallable,
typename ValueCallable,
typename ErrorCallable >
153 auto match_value( NextCallable&& nc, ValueCallable&& vc, ErrorCallable&& ec )
157 std::forward< NextCallable >( nc ),
158 [&vc]( std::tuple< channel_type, payload_message >
const& payload ) {
159 return std::apply( std::forward< ValueCallable >( vc ), payload );
161 std::forward< ErrorCallable >( ec ) );
164 template <
typename... Slotted >
169 []( std::size_t
const ) ->
outcome {
170 return outcome::SUCCESS;
172 [&slotted...]( std::tuple< channel_type, payload_message >
const& payload ) {
173 auto const& [id, data] = payload;
174 return multiplexed_dispatch( id, data, slotted... );
177 return outcome::ERROR;
output_message serialize(output_value const &val)
Definition: endpoint.h:48
void insert(Container &&data)
Definition: endpoint.h:55
std::variant< std::size_t, input_value, error_record > get_value()
Definition: endpoint.h:60
Protocol library has custom type that represents message, however this is just simple overaly over st...
Definition: message.h:40
Definition: multiplexer.h:121
void insert(Container &&data)
Definition: multiplexer.h:141
outcome dispatch_value(Slotted &... slotted)
Definition: multiplexer.h:165
typename Packet::payload_type::template nth_def< 1 > payload_message
Definition: multiplexer.h:124
std::variant< std::size_t, std::tuple< channel_type, payload_message >, error_record > get_value()
Definition: multiplexer.h:147
message_type serialize(channel_type chann, message< N > const &msg)
Definition: multiplexer.h:129
auto match_value(NextCallable &&nc, ValueCallable &&vc, ErrorCallable &&ec)
Definition: multiplexer.h:153
typename Packet::message_type message_type
Definition: multiplexer.h:123
message_type serialize(channel_type chann, sizeless_message< N > const &msg)
Definition: multiplexer.h:135
Sizeless message is class that behaves in a same way as normal message, however it is serialized diff...
Definition: message.h:183
MIT License.
Definition: multiplexer.h:33
uint16_t channel_type
Definition: multiplexer.h:35
outcome extract_multiplexed(std::span< std::byte const > const &msg, BinaryCallable handle_cb)
Definition: multiplexer.h:85
typename multiplexer_payload< N >::value_type multiplexer_value
Definition: multiplexer.h:43
outcome multiplexed_dispatch(channel_type chann, auto const &data, Slotted &... slotted)
Definition: multiplexer.h:103
requires(std::is_enum_v< T >) struct serializer< T
static constexpr T deserialize(std::span< std::byte const, max_size > const &buffer)
Definition: serializer.h:81
static constexpr void serialize_at(std::span< std::byte, max_size > buffer, T item)
Definition: serializer.h:76
std::tuple< multiplexer_enum > multiplexer_service_protocol
Definition: multiplexer.h:59
multiplexer_enum
Definition: multiplexer.h:52
@ PROTOCOL_ERROR
Definition: multiplexer.h:54
@ PORT_MATCH_ERROR
Definition: multiplexer.h:53
static constexpr std::size_t max_size
Definition: serializer.h:73
static constexpr channel_type multiplexer_service_id
Definition: multiplexer.h:57
concept slot
Definition: multiplexer.h:97
typename handler< multiplexer_service_protocol >::message_type multiplexer_service_msg
Definition: multiplexer.h:60
typename multiplexer_payload< N >::message_type multiplexer_message
Definition: multiplexer.h:46
std::tuple< bool, std::span< std::byte > > serialize_multiplexed(channel_type channel, std::span< std::byte const > data, std::span< std::byte > target)
Definition: multiplexer.h:62
constexpr pointer data() noexcept
Returns pointer to first item of the storage.
Definition: static_storage.h:108
decltype(auto) match(Variant &&var, Callables &&... cals)
Definition: match.h:55
T res
Definition: algorithm.h:505
UnaryCallable && f
Definition: algorithm.h:161
outcome represents tristate resut of some operation, which can succeed, fail or produce an error.
Definition: outcome.h:49
handler< T > should be used to execute actual serialization and deserealization of protocol definitio...
Definition: handler.h:39
static message_type serialize(value_type const &val)
Definition: handler.h:45
Definition: serializer.h:38
tuple is high levle alternative to use just 'std::tuple' that is more friendly for standalone protoco...
Definition: tuple.h:43
typename traits::value_type value_type
Definition: tuple.h:57