SRS-control 0.1.4
Loading...
Searching...
No Matches
StructSerializer.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <cstddef>
8#include <expected>
9#include <string_view>
10#include <vector>
11
12namespace srs::process
13{
14 class StructSerializer : public ConverterTask<DataConvertOptions::structure, const StructData*, std::string_view>
15 {
16 public:
17 explicit StructSerializer(size_t n_lines = 1);
18
19 auto convert(const StructData* input, std::vector<char>& output)
20 -> std::expected<std::size_t, std::string_view>;
21
22 auto run(const OutputTo<InputType> auto& prev_data_converter, std::size_t line_number = 0) -> RunResult
23 {
24 auto res = convert(prev_data_converter(line_number), output_data_[line_number]);
25 return res.transform([this, line_number](auto) { return this->operator()(line_number); });
26 }
27
28 [[nodiscard]] auto operator()(std::size_t line_number = 0) const -> OutputType
29 {
30 return std::string_view{ output_data_[line_number].data(), output_data_[line_number].size() };
31 }
32
33 private:
34 std::vector<std::vector<char>> output_data_;
35 };
36} // namespace srs::process
std::expected< OutputType, std::string_view > RunResult
ConverterTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
std::vector< std::vector< char > > output_data_
auto operator()(std::size_t line_number=0) const -> OutputType
auto run(const OutputTo< InputType > auto &prev_data_converter, std::size_t line_number=0) -> RunResult
auto convert(const StructData *input, std::vector< char > &output) -> std::expected< std::size_t, std::string_view >