17 void operator()(
const F& f)
19 if constexpr(std::is_arithmetic_v<F>)
20 r.stream().stream << f;
21 else if constexpr(std::is_aggregate_v<F>)
22 boost::pfr::for_each_field(f, *
this);
23 else if constexpr(avnd::list_ish<F>)
25 r.stream().stream << (int64_t)std::ssize(f);
26 for(
const auto& val : f)
35 template <
typename... Args>
36 void operator()(
const std::variant<Args...>& f)
38 r.stream().stream << (int)f.index();
45 std::function<void(QByteArray)>& bus;
48 void operator()() { this->bus(QByteArray{}); }
51 requires std::is_trivial_v<T>
52 void operator()(
const T& msg)
55 this->bus(QByteArray((
const char*)&msg,
sizeof(msg)));
60 !std::is_trivial_v<T> && avnd::relocatable<T>
61 &&
alignof(T) <=
alignof(max_align_t))
62 void operator()(
const T& msg)
64 QByteArray b(msg.size(), Qt::Uninitialized);
65 auto dst =
reinterpret_cast<T*
>(b.data());
68 this->bus(std::move(b));
73 !std::is_trivial_v<T> && avnd::relocatable<T>
74 &&
alignof(T) <=
alignof(max_align_t))
75 void operator()(T&& msg)
77 QByteArray b(
sizeof(msg), Qt::Uninitialized);
78 auto dst =
reinterpret_cast<T*
>(b.data());
79 std::construct_at(dst, std::move(msg));
81 this->bus(std::move(b));
87 && (!avnd::relocatable<T> || (
alignof(T) >
alignof(max_align_t))))
88 void operator()(
const T& msg)
96 this->bus(std::move(buf));
100 void operator()(
const std::shared_ptr<T>& msg)
103 return (*
this)(std::move(*msg));
105 template <
typename T>
106 void operator()(std::unique_ptr<T> msg)
109 return (*
this)(std::move(*msg));
117 template <
typename F>
118 requires std::is_aggregate_v<F>
119 void operator()(F& f) { boost::pfr::for_each_field(f, *
this); }
121 template <
typename F>
122 requires(std::is_arithmetic_v<F>)
123 void operator()(F& f)
125 r.stream().stream >> f;
128 template <
typename F>
129 requires avnd::list_ish<F>
130 void operator()(F& f)
133 r.stream().stream >> sz;
134 SCORE_ASSERT(sz >= 0);
135 for(int64_t i = 0; i < sz; i++)
137 using type =
typename F::value_type;
140 f.push_back(std::move(val));
144 template <std::size_t I,
typename... Args>
145 bool write_variant(std::variant<Args...>& f)
147 auto& elt = f.template emplace<I>();
152 template <
typename... Args>
153 void operator()(std::variant<Args...>& f)
156 r.stream().stream >> index;
158 SCORE_ASSERT(index >= 0);
159 SCORE_ASSERT(index <
sizeof...(Args));
160 [&]<std::size_t... I>(std::index_sequence<I...>)
162 (((index == I) && write_variant<I>(f)) || ...);
164 (std::make_index_sequence<
sizeof...(Args)>{});
167 void operator()(
auto& f) { r.stream() >> f; }