SRS-control 0.1.4
 
Loading...
Searching...
No Matches
ProtoSerializerBase.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <srs/data/message.pb.h>
5#include <utility>
6
7namespace srs::process
8{
9 template <typename Converter>
10 class ProtoSerializerBase : public DataConverterBase<const proto::Data*, std::string_view>
11 {
12 public:
13 explicit ProtoSerializerBase(asio::thread_pool& thread_pool, std::string name, Converter converter)
14 : DataConverterBase{ generate_coro(thread_pool.get_executor()) }
15 , name_{ std::move(name) }
16 , converter_{ converter }
17 {
18 }
19 [[nodiscard]] auto data() const -> std::string_view { return output_data_; }
20
21 private:
22 std::string name_;
23 std::string output_data_;
24 Converter converter_;
25
26 void reset() { output_data_.clear(); }
27
28 // NOLINTNEXTLINE(readability-static-accessed-through-instance)
29 auto generate_coro(asio::any_io_executor /*unused*/) -> CoroType
30 {
31 InputType temp_data{};
32 while (true)
33 {
34 if (temp_data != nullptr)
35 {
36 reset();
37 converter_(*temp_data, output_data_);
38 }
39 auto data = co_yield (std::string_view{ output_data_ });
40 if (data.has_value())
41 {
42 temp_data = data.value();
43 }
44 else
45 {
46 spdlog::debug("Shutting down {:?} serializer.", name_);
47 co_return;
48 }
49 }
50 }
51 };
52
53} // namespace srs
asio::experimental::coro< OutputType(std::optional< InputType >)> CoroType
auto generate_coro(asio::any_io_executor) -> CoroType
auto data() const -> std::string_view
ProtoSerializerBase(asio::thread_pool &thread_pool, std::string name, Converter converter)