10#include "introspect.hpp"
11#include "processor.hpp"
22template <
typename Downstream>
class view_as_bytes {
23 static_assert(processor<Downstream, bucket<std::byte>>);
25 Downstream downstream;
28 explicit view_as_bytes(Downstream downstream)
29 : downstream(std::move(downstream)) {}
31 [[nodiscard]]
auto introspect_node() const -> processor_info {
32 return processor_info(
this,
"view_as_bytes");
35 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
36 return downstream.introspect_graph().push_entry_point(
this);
39 template <
typename Event>
40 requires std::is_trivial_v<Event>
41 void handle(Event
const &event) {
44 auto const_byte_span = std::as_bytes(std::span(&event, 1));
46 const_cast<std::byte *
>(const_byte_span.data()),
47 const_byte_span.size()));
52 requires std::is_trivial_v<T>
53 void handle(bucket<T>
const &event) {
56 auto const_byte_span = std::as_bytes(std::span(event));
58 const_cast<std::byte *
>(const_byte_span.data()),
59 const_byte_span.size()));
63 void flush() { downstream.flush(); }
90template <
typename Downstream>
auto view_as_bytes(Downstream downstream) {
91 return internal::view_as_bytes<Downstream>(std::move(downstream));
auto ad_hoc_bucket(std::span< T > s) -> bucket< T >
Create a tcspc::bucket referencing a span.
Definition bucket.hpp:489
auto view_as_bytes(Downstream downstream)
Create a processor that views events as byte spans.
Definition view_as_bytes.hpp:90
libtcspc namespace.
Definition acquire.hpp:29