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 requires std::is_trivial_v<T>
49 void operator()(
const T& msg)
52 this->bus(QByteArray((
const char*)&msg,
sizeof(msg)));
57 !std::is_trivial_v<T> && avnd::relocatable<T>
58 &&
alignof(T) <=
alignof(max_align_t))
59 void operator()(
const T& msg)
61 QByteArray b(msg.size(), Qt::Uninitialized);
62 auto dst =
reinterpret_cast<T*
>(b.data());
65 this->bus(std::move(b));
70 !std::is_trivial_v<T> && avnd::relocatable<T>
71 &&
alignof(T) <=
alignof(max_align_t))
72 void operator()(T&& msg)
74 QByteArray b(
sizeof(msg), Qt::Uninitialized);
75 auto dst =
reinterpret_cast<T*
>(b.data());
76 std::construct_at(dst, std::move(msg));
78 this->bus(std::move(b));
84 && (!avnd::relocatable<T> || (
alignof(T) >
alignof(max_align_t))))
85 void operator()(
const T& msg)
93 this->bus(std::move(buf));
97 void operator()(
const std::shared_ptr<T>& msg)
100 return (*
this)(std::move(*msg));
102 template <
typename T>
103 void operator()(std::unique_ptr<T> msg)
106 return (*
this)(std::move(*msg));
114 template <
typename F>
115 requires std::is_aggregate_v<F>
116 void operator()(F& f) { boost::pfr::for_each_field(f, *
this); }
118 template <
typename F>
119 requires(std::is_arithmetic_v<F>)
120 void operator()(F& f)
122 r.stream().stream >> f;
125 template <
typename F>
126 requires avnd::list_ish<F>
127 void operator()(F& f)
130 r.stream().stream >> sz;
131 SCORE_ASSERT(sz >= 0);
132 for(int64_t i = 0; i < sz; i++)
134 using type =
typename F::value_type;
137 f.push_back(std::move(val));
141 template <std::size_t I,
typename... Args>
142 bool write_variant(std::variant<Args...>& f)
144 auto& elt = f.template emplace<I>();
149 template <
typename... Args>
150 void operator()(std::variant<Args...>& f)
153 r.stream().stream >> index;
155 SCORE_ASSERT(index >= 0);
156 SCORE_ASSERT(index <
sizeof...(Args));
157 [&]<std::size_t... I>(std::index_sequence<I...>)
159 (((index == I) && write_variant<I>(f)) || ...);
161 (std::make_index_sequence<
sizeof...(Args)>{});
164 void operator()(
auto& f) { r.stream() >> f; }