emlabcpp
modern opinionated embedded C++ library
endpoint.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include "./packet_handler.h"
27 
28 namespace emlabcpp::protocol
29 {
30 
32 {
33 };
34 
35 using endpoint_error = std::variant< error_record, endpoint_load_error >;
36 
37 template < typename InputPacket, typename OutputPacket >
38 class endpoint
39 {
40 
41 public:
42  using sequencer_type = typename InputPacket::sequencer_type;
43  using output_message = typename OutputPacket::message_type;
44  using input_message = typename InputPacket::message_type;
47 
49  {
51  return handler::serialize( val );
52  }
53 
54  template < typename Container >
55  void insert( Container&& data )
56  {
57  seq_.insert( std::forward< Container >( data ) );
58  }
59 
60  std::variant< std::size_t, input_value, error_record > get_value()
61  {
62  using return_type = std::variant< std::size_t, input_value, error_record >;
64 
65  return match(
66  seq_.get_message(),
67  []( sequencer_read_request const to_read ) -> return_type {
68  return *to_read;
69  },
70  [&]( input_message const msg ) -> return_type {
71  return match( handler::extract( msg ), convert_to< return_type >{} );
72  } );
73  }
74 
75 private:
76  sequencer_type seq_;
77 };
78 
79 } // namespace emlabcpp::protocol
Definition: endpoint.h:39
typename OutputPacket::message_type output_message
Definition: endpoint.h:43
output_message serialize(output_value const &val)
Definition: endpoint.h:48
void insert(Container &&data)
Definition: endpoint.h:55
typename InputPacket::sequencer_type sequencer_type
Definition: endpoint.h:42
typename InputPacket::value_type input_value
Definition: endpoint.h:46
typename OutputPacket::value_type output_value
Definition: endpoint.h:45
std::variant< std::size_t, input_value, error_record > get_value()
Definition: endpoint.h:60
typename InputPacket::message_type input_message
Definition: endpoint.h:44
MIT License.
Definition: multiplexer.h:33
std::variant< error_record, endpoint_load_error > endpoint_error
Definition: endpoint.h:35
std::variant< int64_t, float, bool, string_buffer > value_type
Definition: base.h:51
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
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: packet_handler.h:36