SRS-control 0.1.4
Loading...
Searching...
No Matches
StructDeserializer.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <bitset>
8#include <boost/asio/any_io_executor.hpp>
9#include <boost/asio/thread_pool.hpp>
10#include <cassert>
11#include <cstddef>
12#include <expected>
13#include <string_view>
14#include <vector>
15#include <zpp_bits.h>
16
17#include <srs/Application.hpp>
19
20namespace srs::workflow
21{
22 class TaskDiagram;
23}
24
25namespace srs::process
26{
27 class StructDeserializer : public ConverterTask<DataConvertOptions::structure, std::string_view, const StructData*>
28 {
29 public:
30 using DataElementType = std::bitset<common::HIT_DATA_BIT_LENGTH>;
31 using ReceiveDataSquence = std::vector<DataElementType>;
32 explicit StructDeserializer(size_t n_lines = 1);
33
34 [[nodiscard]] auto operator()(std::size_t line_number = 0) const -> OutputType
35 {
36 assert(line_number < get_n_lines());
37 return &output_data_[line_number];
38 }
39
40 auto run(const OutputTo<InputType> auto& prev_data_converter, std::size_t line_number = 0) -> RunResult
41 {
42 assert(line_number < get_n_lines());
43 auto& output_data = output_data_[line_number];
44 auto& raw_body_part_data = raw_body_part_data_[line_number];
45 reset_struct_data(output_data);
46 raw_body_part_data.clear();
47 auto res = convert(prev_data_converter(line_number), output_data, raw_body_part_data);
48 return res.transform([line_number, this](auto) { return this->operator()(line_number); });
49 }
50
51 private:
52 std::vector<ReceiveDataSquence> raw_body_part_data_;
53 std::vector<StructData> output_data_;
54
55 static auto convert(std::string_view binary_data, StructData& output, ReceiveDataSquence& body_part_data)
56 -> std::expected<std::size_t, std::string_view>;
57 static void translate_raw_data(StructData& struct_data, ReceiveDataSquence& receive_raw_data);
58 static void byte_reverse_data_sq(ReceiveDataSquence& receive_raw_data);
59 static auto check_is_hit(const DataElementType& element) -> bool
60 {
61 return element.test(common::FLAG_BIT_POSITION);
62 }
63 };
64
65} // 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< StructData > output_data_
static void translate_raw_data(StructData &struct_data, ReceiveDataSquence &receive_raw_data)
static auto convert(std::string_view binary_data, StructData &output, ReceiveDataSquence &body_part_data) -> std::expected< std::size_t, std::string_view >
std::vector< DataElementType > ReceiveDataSquence
std::bitset< common::HIT_DATA_BIT_LENGTH > DataElementType
auto run(const OutputTo< InputType > auto &prev_data_converter, std::size_t line_number=0) -> RunResult
static auto check_is_hit(const DataElementType &element) -> bool
std::vector< ReceiveDataSquence > raw_body_part_data_
auto operator()(std::size_t line_number=0) const -> OutputType
static void byte_reverse_data_sq(ReceiveDataSquence &receive_raw_data)
constexpr auto FLAG_BIT_POSITION
void reset_struct_data(StructData &struct_data)