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 avnd::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)
121 avnd::pfr::for_each_field(f, *
this);
124 template <
typename F>
125 requires(std::is_arithmetic_v<F>)
126 void operator()(F& f)
128 r.stream().stream >> f;
131 template <
typename F>
132 requires avnd::list_ish<F>
133 void operator()(F& f)
136 r.stream().stream >> sz;
137 SCORE_ASSERT(sz >= 0);
138 for(int64_t i = 0; i < sz; i++)
140 using type =
typename F::value_type;
143 f.push_back(std::move(val));
147 template <std::size_t I,
typename... Args>
148 bool write_variant(std::variant<Args...>& f)
150 auto& elt = f.template emplace<I>();
155 template <
typename... Args>
156 void operator()(std::variant<Args...>& f)
159 r.stream().stream >> index;
161 SCORE_ASSERT(index >= 0);
162 SCORE_ASSERT(index <
sizeof...(Args));
163 [&]<std::size_t... I>(std::index_sequence<I...>)
165 (((index == I) && write_variant<I>(f)) || ...);
167 (std::make_index_sequence<
sizeof...(Args)>{});
170 void operator()(
auto& f) { r.stream() >> f; }