SRS-control 0.1.4
 
Loading...
Searching...
No Matches
RawToDelimRawConveter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <zpp_bits.h>
4
6
7namespace srs::process
8{
9 class Raw2DelimRawConverter : public DataConverterBase<std::string_view, std::string_view>
10 {
11 public:
12 explicit Raw2DelimRawConverter(asio::thread_pool& thread_pool)
13 : DataConverterBase{ generate_coro(thread_pool.get_executor()) }
14 {
15 }
16
18 static constexpr auto ConverterOption = std::array{ raw_frame };
19
20 [[nodiscard]] auto data() const -> OutputType
21 {
22 return std::string_view{ output_data_.data(), output_data_.size() };
23 }
24
25 private:
26 std::vector<char> output_data_;
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 (not temp_data.empty())
35 {
36 output_data_.clear();
37 convert(temp_data, output_data_);
38 }
39 auto output_temp = std::string_view{ output_data_.data(), output_data_.size() };
40 auto data = co_yield (output_temp);
41 if (data.has_value())
42 {
43 temp_data = data.value();
44 }
45 else
46 {
47 spdlog::debug("Shutting down Raw2DelimRaw converter.");
48 co_return;
49 }
50 }
51 }
52
53 static void convert(std::string_view input, std::vector<char>& output)
54 {
55 auto size = static_cast<SizeType>(input.size());
56 output.reserve(size + sizeof(size));
57 auto deserialize_to = zpp::bits::out{ output, zpp::bits::append{}, zpp::bits::endian::big{} };
58 deserialize_to(size, zpp::bits::unsized(input)).or_throw();
59 }
60 };
61} // namespace srs
asio::experimental::coro< OutputType(std::optional< InputType >)> CoroType
Raw2DelimRawConverter(asio::thread_pool &thread_pool)
static void convert(std::string_view input, std::vector< char > &output)
auto generate_coro(asio::any_io_executor) -> CoroType
uint32_t RawDelimSizeType