aboutsummaryrefslogtreecommitdiff
path: root/apps/SoilMoistureIo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/SoilMoistureIo.cpp')
-rw-r--r--apps/SoilMoistureIo.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/apps/SoilMoistureIo.cpp b/apps/SoilMoistureIo.cpp
index c9cfa1e..40f2f7a 100644
--- a/apps/SoilMoistureIo.cpp
+++ b/apps/SoilMoistureIo.cpp
@@ -174,7 +174,7 @@ void SqlSampleOutputStream::write(SampleRecord values) {
// (*stream.get()) << "INSERT INTO " << table_name << "(" << fs << ") VALUES(" << vs << ");" << endl;
}
-void CsvSampleParser::process(mutable_buffers_1 buffer) {
+void KeyValueSampleParser::process(mutable_buffers_1 buffer) {
size_t size = buffer_size(buffer);
@@ -199,14 +199,14 @@ void CsvSampleParser::process(mutable_buffers_1 buffer) {
}
-void CsvSampleParser::process_line(shared_ptr<vector<uint8_t>> packet) {
+void KeyValueSampleParser::process_line(shared_ptr<vector<uint8_t>> packet) {
auto timestamp = std::chrono::system_clock::now().time_since_epoch().count();
auto s = std::string((char *) packet->data(), packet->size());
static const boost::regex e("([_a-zA-Z0-9]+)=([0-9]+)");
- std::string::const_iterator start = s.begin();
- std::string::const_iterator end = s.end();
+ auto start = s.cbegin();
+ auto end = s.cend();
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
@@ -217,9 +217,6 @@ void CsvSampleParser::process_line(shared_ptr<vector<uint8_t>> packet) {
auto value = static_cast<string>(what[2]);
start = what[0].second;
-
-
-
auto key = dict.indexOf(name);
sample.set(key, value);
@@ -231,10 +228,10 @@ void CsvSampleParser::process_line(shared_ptr<vector<uint8_t>> packet) {
}
AutoSampleParser::AutoSampleParser(shared_ptr<SampleOutputStream> output, KeyDictionary &dict) :
- SampleStreamParser(sample_format_type::AUTO), csvParser(new CsvSampleParser(output, dict)) {
+ SampleStreamParser(sample_format_type::AUTO), keyValueParser(new KeyValueSampleParser(output, dict)) {
// Directly select the parser now until we have more than one parser
- parser = std::move(csvParser);
- type_ = sample_format_type::CSV;
+ parser = std::move(keyValueParser);
+ type_ = sample_format_type::KEY_VALUE;
}
void AutoSampleParser::process(mutable_buffers_1 buffer) {
@@ -252,6 +249,8 @@ string to_string(const sample_format_type &arg) {
return "csv";
else if (arg == sample_format_type::JSON)
return "json";
+ else if (arg == sample_format_type::KEY_VALUE)
+ return "key-value";
else if (arg == sample_format_type::SQL)
return "sql";
else
@@ -262,8 +261,8 @@ unique_ptr<SampleStreamParser> open_sample_input_stream(
shared_ptr<SampleOutputStream> output,
KeyDictionary &dict,
sample_format_type type) {
- if (type == sample_format_type::CSV) {
- return make_unique<CsvSampleParser>(output, dict);
+ if (type == sample_format_type::KEY_VALUE) {
+ return make_unique<KeyValueSampleParser>(output, dict);
} else if (type == sample_format_type::AUTO) {
return make_unique<AutoSampleParser>(output, dict);
} else {