8#include <slick/queue.hpp>
9#include <slick/stream_buffer_multiplexer.hpp>
15using producer_buffer = slick::stream_buffer_multiplexer::producer_buffer;
21 template<
typename T,
typename populate_event_fn>
22 static bool publish(slick::SlickQueue<uint8_t>& queue, uint32_t size, populate_event_fn &&populate_event_func) {
23 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
24 auto index = queue.reserve(size);
25 auto *e =
new (queue[index]) T();
26 populate_event_func(*e);
27 queue.publish(index, size);
31 template<
typename T,
typename populate_event_fn>
32 static bool publish(slick::SlickQueue<uint8_t>& queue, populate_event_fn &&populate_event_func) {
33 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
34 auto index = queue.reserve(
sizeof(T));
35 auto *e =
new (queue[index]) T();
36 populate_event_func(*e);
37 queue.publish(index,
sizeof(T));
43 static bool publish(slick::SlickQueue<uint8_t>& queue,
const T& event) {
44 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
45 auto index = queue.reserve(
sizeof(T));
46 auto *e =
reinterpret_cast<T*
>(queue[index]);
48 queue.publish(index,
sizeof(T));
54 static T*
consume(slick::SlickQueue<uint8_t>& queue, uint64_t& cursor) {
55 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
56 auto [data, size] = queue.read(cursor);
57 if (data && size >=
sizeof(T)) {
58 return reinterpret_cast<T*
>(data);
64 template<
typename T,
typename populate_event_fn>
66 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
67 auto [ptr, sz] = buffer.prepare(size);
68 auto *e =
new (ptr) T();
69 populate_event_func(*e);
75 template<
typename T,
typename populate_event_fn>
77 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
78 auto [ptr, sz] = buffer.prepare(
sizeof(T));
79 auto *e =
new (ptr) T();
80 populate_event_func(*e);
81 buffer.commit(
sizeof(T));
82 buffer.consume(
sizeof(T));
89 static_assert(std::is_trivially_copyable_v<T>,
"Event must be trivially copyable");
90 auto [ptr, sz] = buffer.prepare(
sizeof(T));
91 auto *e =
reinterpret_cast<T*
>(ptr);
93 buffer.commit(
sizeof(T));
94 buffer.consume(
sizeof(T));
static bool publish(producer_buffer &buffer, uint32_t size, populate_event_fn &&populate_event_func)
static bool publish(slick::SlickQueue< uint8_t > &queue, uint32_t size, populate_event_fn &&populate_event_func)
static bool publish(slick::SlickQueue< uint8_t > &queue, const T &event)
static bool publish(slick::SlickQueue< uint8_t > &queue, populate_event_fn &&populate_event_func)
static T * consume(slick::SlickQueue< uint8_t > &queue, uint64_t &cursor)
static bool publish(producer_buffer &buffer, const T &event)
static bool publish(producer_buffer &buffer, populate_event_fn &&populate_event_func)
slick::stream_buffer_multiplexer::producer_buffer producer_buffer