本文整理汇总了C++中message::extract_opts方法的典型用法代码示例。如果您正苦于以下问题:C++ message::extract_opts方法的具体用法?C++ message::extract_opts怎么用?C++ message::extract_opts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message
的用法示例。
在下文中一共展示了message::extract_opts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spawn
trial<actor> spawn(message const& params) {
auto schema_file = ""s;
auto output = "-"s;
auto r = params.extract_opts({
{"schema,s", "alternate schema file", schema_file},
{"write,w", "path to write events to", output},
{"uds,u", "treat -w as UNIX domain socket to connect to"}
});
// Setup a custom schema.
schema sch;
if (!schema_file.empty()) {
auto t = load_contents(schema_file);
if (!t)
return t.error();
auto s = to<schema>(*t);
if (!s)
return error{"failed to load schema"};
sch = std::move(*s);
}
// Facilitate actor shutdown when returning with error.
actor snk;
auto guard = make_scope_guard([&] { anon_send_exit(snk, exit::error); });
// The "pcap" and "bro" sink manually handle file output. All other
// sources are file-based and we setup their input stream here.
auto& format = params.get_as<std::string>(0);
std::unique_ptr<std::ostream> out;
if (!(format == "pcap" || format == "bro")) {
if (r.opts.count("uds") > 0) {
if (output == "-")
return error{"cannot use stdout as UNIX domain socket"};
auto uds = util::unix_domain_socket::connect(output);
if (!uds)
return error{"failed to connect to UNIX domain socket at ", output};
auto remote_fd = uds.recv_fd(); // Blocks!
out = std::make_unique<util::fdostream>(remote_fd);
} else if (output == "-") {
out = std::make_unique<util::fdostream>(1); // stdout
} else {
out = std::make_unique<std::ofstream>(output);
}
}
if (format == "pcap") {
#ifndef VAST_HAVE_PCAP
return error{"not compiled with pcap support"};
#else
auto flush = 10000u;
r = r.remainder.extract_opts({
{"flush,f", "flush to disk after this many packets", flush}
});
if (!r.error.empty())
return error{std::move(r.error)};
snk = caf::spawn<priority_aware>(pcap, sch, output, flush);
#endif
} else if (format == "bro") {
snk = caf::spawn(bro, output);
} else if (format == "csv") {
snk = caf::spawn(csv, std::move(out));
} else if (format == "ascii") {
snk = caf::spawn(ascii, std::move(out));
} else if (format == "json") {
r = r.remainder.extract_opts({
{"flatten,f", "flatten records"}
});
snk = caf::spawn(sink::json, std::move(out), r.opts.count("flatten") > 0);
// FIXME: currently the "vast export" command cannot take sink parameters,
// which is why we add a hacky convenience sink called "flat-json". We should
// have a command line format akin to "vast export json -f query ...",
// which would allow passing both sink and exporter arguments.
} else if (format == "flat-json") {
snk = caf::spawn(sink::json, std::move(out), true);
} else {
return error{"invalid export format: ", format};
}
guard.disable();
return snk;
}