emlabcpp
modern opinionated embedded C++ library
base.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include "../bounded.h"
27 #include "./error.h"
28 
29 #include <bit>
30 #include <bitset>
31 #include <cstring>
32 #include <type_traits>
33 #include <variant>
34 
35 namespace emlabcpp::protocol
36 {
37 
39 {
40 
41  std::size_t used = 0;
42  mark const* error = nullptr;
43 
44  constexpr conversion_result() = default;
45 
46  explicit constexpr conversion_result( std::size_t const u )
47  : used( u )
48  {
49  }
50 
51  constexpr conversion_result( std::size_t const u, mark const* const m )
52  : used( u )
53  , error( m )
54  {
55  }
56 
57  [[nodiscard]] constexpr bool has_error() const
58  {
59  return error != nullptr;
60  }
61 
62  [[nodiscard]] constexpr mark const* get_error() const
63  {
64  return error;
65  }
66 };
67 
69 template < typename T >
70 concept base_type = std::is_floating_point_v< T > || std::is_integral_v< T > || std::is_enum_v< T >;
71 
75 
77 template < std::endian Endianess, typename D >
79 {
80  static constexpr std::endian value = Endianess;
81  using def_type = D;
82 };
83 
87 template < typename... Ds >
88 struct group
89 {
90  using def_type = std::variant< Ds... >;
91 };
92 
93 template < typename... Ds >
94 struct tag_group
95 {
96  using def_type = std::variant< Ds... >;
97 };
98 
102 template < typename CounterDef, typename D >
104 {
105  using counter_type = CounterDef;
106  using def_type = D;
107 };
108 
111 template < typename D, auto Offset >
113 {
114  static constexpr auto offset = Offset;
115  using def_type = D;
116 };
117 
122 {
123 };
124 
125 } // namespace emlabcpp::protocol
MIT License.
Definition: multiplexer.h:33
std::variant< Ds... > def_type
Definition: base.h:96
Endianess
Definition: serializer.h:70
CounterDef counter_type
Definition: base.h:105
D def_type
Definition: base.h:106
concept base_type
Concept that matches types considered base - serialized directly by using byte shifting.
Definition: base.h:70
std::variant< Ds... > def_type
Definition: base.h:90
Serializes values from definitions Ds to std::variant.
Definition: base.h:89
Creates a segment starting with counter defined by CounterDef, this counter limits how many bytes are...
Definition: base.h:104
Definition: base.h:95
mark const * error
Definition: base.h:42
constexpr bool has_error() const
Definition: base.h:57
constexpr mark const * get_error() const
Definition: base.h:62
constexpr conversion_result(std::size_t const u)
Definition: base.h:46
std::size_t used
Definition: base.h:41
constexpr conversion_result(std::size_t const u, mark const *const m)
Definition: base.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
static constexpr std::endian value
Definition: base.h:80
The value defined by D present in the message is offseted by Offset.
Definition: base.h:113
static constexpr auto offset
Definition: base.h:114
D def_type
Definition: base.h:115