CppSerdes  1.0
A serialization/deserialization library designed with embedded systems in mind
serdes_formatter.h
Go to the documentation of this file.
1 #ifndef _SERDES_FORMATTER_H_
8 #define _SERDES_FORMATTER_H_
9 
10 #include <functional>
11 #include "bitcpy_common.h"
12 
14 namespace serdes
15 {
16  struct packet; // forward declaration
17 
32  struct formatter
33  {
35  std::function<void(packet &)> formatter_lambda;
36  };
37 
40  constexpr void (*pure_virtual_formatter)(packet &) = nullptr;
41 
44  inline void virtual_formatter(packet &) {}
45 
46  namespace detail
47  {
48  template <>
49  struct default_bitsize<formatter>
50  {
51  static constexpr size_t value = 0u;
52  };
53  }
54 
58  namespace init_formatter
59  {
60  // this namespace exists only to help user with intellisense use autocomplete
61  // to find the init_formatter macro, and see the help documentation above
62  }
63 
68  {
69  // this namespace exists only to help user with intellisense use autocomplete
70  // to find the init_this_formatter macro, and see the help documentation above
71  }
72 }
73 
77 #define init_formatter(...) \
78  formatter \
79  { \
80  [&](serdes::packet &_p_k_t) { _p_k_t.add(__VA_ARGS__); } \
81  }
82 
86 #define init_this_formatter(...) \
87  formatter \
88  { \
89  [&, this](serdes::packet &_p_k_t) { _p_k_t.add(__VA_ARGS__); } \
90  }
91 
92 #endif // _SERDES_FORMATTER_H_
Defines common bitcpy details as well as a info::version number, and bit_length function.
void virtual_formatter(packet &)
used to initialize a formatter object to be optionally overridable. the default behaviour if not over...
Definition: serdes_formatter.h:44
#define init_this_formatter(...)
init_this_formatter() constructs a serdes::formatter object lambda without using dynamic memory alloc...
Definition: serdes_formatter.h:86
constexpr void(* pure_virtual_formatter)(packet &)
used to initialize a formatter object to be required but uninitialized. the default behaviour if not ...
Definition: serdes_formatter.h:40
a serialization/deserialization helper class, with load, store, and stream operators ...
Definition: serdes.h:24
CppSerdes library namespace.
Definition: bitcpy_common.h:69
a lambda function wrapper that can describe any serialization/deserialization formatting process...
Definition: serdes_formatter.h:32
std::function< void(packet &)> formatter_lambda
the formatting function taking a packet process (and any captures) as instructions ...
Definition: serdes_formatter.h:35
#define init_formatter(...)
init_formatter() constructs a serdes::formatter object lambda without using dynamic memory allocation...
Definition: serdes_formatter.h:77