YPC  0.2.0
first_match_parser.h
1 #include "ypc/corecommon/package.h"
2 #include "ypc/stbox/ebyte.h"
3 #include "ypc/stbox/stx_common.h"
4 #ifdef EXAMPLE_FM_NORMAL
5 #include <glog/logging.h>
6 typedef ypc::bytes bytes;
7 #else
8 #include "ypc/core_t/analyzer/data_source.h"
9 #include "ypc/stbox/tsgx/log.h"
10 typedef stbox::bytes bytes;
11 #endif
12 #include "user_type.h"
13 #include "ypc/corecommon/data_source.h"
14 #include "ypc/corecommon/to_type.h"
15 #include <hpda/extractor/raw_data.h>
16 #include <hpda/output/memory_output.h>
17 #include <hpda/processor/query/filter.h>
18 #include <string.h>
19 
20 define_nt(input_buf, std::string);
21 typedef ff::net::ntpackage<0, input_buf> input_buf_t;
22 
23 class first_match_parser {
24 public:
26  first_match_parser(ypc::data_source<bytes> *source) : m_source(source){};
27 
28  inline bytes do_parse(const bytes &param) {
29  LOG(INFO) << "do parse";
30  ypc::to_type<bytes, user_item_t> converter(m_source);
31  // param must be serialized ntpackage
33  int counter = 0;
35  &converter, [&](const user_item_t &v) {
36  counter++;
37  std::string zjhm = v.get<ZJHM>();
38  if (zjhm == pkg.get<input_buf>()) {
39  return true;
40  }
41  return false;
42  });
43 
45  mo.get_engine()->run();
46  LOG(INFO) << "do parse done";
47 
48  bytes result;
49  for (auto it : mo.values()) {
50  stbox::printf("found\n");
51  result += it.get<XM>();
52  result += " : ";
53  result += it.get<ZJHM>();
54  result += " .";
55  }
56  return result;
57  }
58 
59  inline bool merge_parse_result(const std::vector<bytes> &block_result,
60  const bytes &param, bytes &result) {
61  bytes s;
62  for (auto k : block_result) {
63  s = s + k;
64  }
65  result = s;
66  return false;
67  }
68 
69 protected:
70  ypc::data_source<bytes> *m_source;
71 };
first_match_parser
Definition: first_match_parser.h:24
hpda::processor::internal::filter_impl
Definition: filter.h:9
ypc::data_source< bytes >
ypc::utc::bytes
Definition: bytes.h:143
hpda::output::internal::memory_output_impl
Definition: memory_output.h:9
ypc::to_type
Definition: to_type.h:15
ypc::make_package
Definition: package.h:48