YPC  0.2.0
to_type.h
1 #pragma once
2 #include "hpda/processor/processor_base.h"
3 #include "ypc/core_t/analyzer/ntpackage_item_parser.h"
4 #include "ypc/corecommon/nt_cols.h"
5 //#include "ypc_t/ecommon/package.h"
6 #include <ff/util/ntobject.h>
7 
8 namespace ypc {
9 
10 // using bytes = ::stbox::bytes;
11 // typedef ::ff::util::ntobject<nt<bytes>::data> data_source_output_t;
12 template <typename BytesType, typename NTObj>
13 class to_type : public ::hpda::processor::internal::processor_base<
14  ::ff::util::ntobject<typename nt<BytesType>::data>, NTObj> {
15 public:
16  typedef ::ff::util::ntobject<typename nt<BytesType>::data>
17  data_source_output_t;
19  *upper_stream)
20  : hpda::processor::internal::processor_base<data_source_output_t, NTObj>(
21  upper_stream) {}
22 
23  typedef ::hpda::processor::internal::processor_base<data_source_output_t,
24  NTObj>
25  base;
26  virtual bool process() {
27  if (!base::has_input_value()) {
28  return false;
29  }
30 
31  using ntt = nt<BytesType>;
32  const BytesType &data =
33  base::input_value().template get<typename ntt::data>();
34  try {
35 
36  m_data = ntpackage_item_parser<typename BytesType::byte_t, NTObj>::parser(
37  data.data(), data.size());
38  } catch (const std::exception &e) {
39  LOG(ERROR) << "failed to convert to type";
40  return false;
41  }
42  base::consume_input_value();
43  return true;
44  }
45 
46  virtual NTObj output_value() { return m_data; }
47 
48 protected:
49  NTObj m_data;
50 };
51 } // namespace ypc
hpda::processor::internal::processor_base
Definition: processor_base.h:9
ypc::nt
Definition: nt_cols.h:6
hpda::internal::processor_with_output< data_source_output_t >