diff --git a/lib/formats/column.cpp b/lib/formats/column.cpp index c04b4af01..f3318754f 100644 --- a/lib/formats/column.cpp +++ b/lib/formats/column.cpp @@ -21,33 +21,43 @@ size_t ColumnLineFormat::sprintLine(char *buf, size_t len, const struct Sample *smp) { size_t off = 0; - if (smp->flags & (int)SampleFlags::HAS_TS_ORIGIN) - off += snprintf(buf + off, len - off, "%lld%c%09lld", - (long long)smp->ts.origin.tv_sec, separator, - (long long)smp->ts.origin.tv_nsec); - else - off += snprintf(buf + off, len - off, "nan%cnan", separator); + if (flags & (int)SampleFlags::HAS_TS_ORIGIN) { + if (smp->flags & (int)SampleFlags::HAS_TS_ORIGIN) + off += snprintf(buf + off, len - off, "%lld%c%09lld", + (long long)smp->ts.origin.tv_sec, separator, + (long long)smp->ts.origin.tv_nsec); + else + off += snprintf(buf + off, len - off, "nan%cnan", separator); + } - if (smp->flags & (int)SampleFlags::HAS_TS_RECEIVED) - off += snprintf(buf + off, len - off, "%c%.09f", separator, - time_delta(&smp->ts.origin, &smp->ts.received)); - else - off += snprintf(buf + off, len - off, "%cnan", separator); + if (flags & (int)SampleFlags::HAS_OFFSET) { + if (smp->flags & (int)SampleFlags::HAS_TS_RECEIVED) { + auto offset = time_delta(&smp->ts.origin, &smp->ts.received); + off += snprintf(buf + off, len - off, "%c%.09f", separator, offset); + } else + off += snprintf(buf + off, len - off, "%cnan", separator); + } - if (smp->flags & (int)SampleFlags::HAS_SEQUENCE) - off += - snprintf(buf + off, len - off, "%c%" PRIu64, separator, smp->sequence); - else - off += snprintf(buf + off, len - off, "%cnan", separator); + if (flags & (int)SampleFlags::HAS_SEQUENCE) { + if (smp->flags & (int)SampleFlags::HAS_SEQUENCE) + off += snprintf(buf + off, len - off, "%c%" PRIu64, separator, + smp->sequence); + else + off += snprintf(buf + off, len - off, "%cnan", separator); + } - for (unsigned i = 0; i < smp->length; i++) { - auto sig = smp->signals->getByIndex(i); - if (!sig) - break; + if (flags & (int)SampleFlags::HAS_DATA) { + if (smp->flags & (int)SampleFlags::HAS_DATA) { + for (unsigned i = 0; i < smp->length; i++) { + auto sig = smp->signals->getByIndex(i); + if (!sig) + break; - off += snprintf(buf + off, len - off, "%c", separator); - off += smp->data[i].printString(sig->type, buf + off, len - off, - real_precision); + off += snprintf(buf + off, len - off, "%c", separator); + off += smp->data[i].printString(sig->type, buf + off, len - off, + real_precision); + } + } } off += snprintf(buf + off, len - off, "%c", delimiter); @@ -186,18 +196,18 @@ void ColumnLineFormat::parse(json_t *json) { // Register formats static char n1[] = "csv"; static char d1[] = "Comma-separated values"; -static ColumnLineFormatPlugin +static ColumnLineFormatPlugin< + n1, d1, + (int)SampleFlags::HAS_TS_ORIGIN | (int)SampleFlags::HAS_SEQUENCE | + (int)SampleFlags::HAS_OFFSET | (int)SampleFlags::HAS_DATA, + '\n', ','> p1; static char n2[] = "tsv"; static char d2[] = "Tabulator-separated values"; -static ColumnLineFormatPlugin +static ColumnLineFormatPlugin< + n2, d2, + (int)SampleFlags::HAS_TS_ORIGIN | (int)SampleFlags::HAS_SEQUENCE | + (int)SampleFlags::HAS_OFFSET | (int)SampleFlags::HAS_DATA, + '\n', '\t'> p2; diff --git a/lib/formats/villas_human.cpp b/lib/formats/villas_human.cpp index f0190b1f5..61687a2b4 100644 --- a/lib/formats/villas_human.cpp +++ b/lib/formats/villas_human.cpp @@ -32,9 +32,9 @@ size_t VILLASHumanFormat::sprintLine(char *buf, size_t len, } if (flags & (int)SampleFlags::HAS_OFFSET) { + auto offset = time_delta(&smp->ts.origin, &smp->ts.received); if (smp->flags & (int)SampleFlags::HAS_TS_RECEIVED) - off += snprintf(buf + off, len - off, "%+e", - time_delta(&smp->ts.origin, &smp->ts.received)); + off += snprintf(buf + off, len - off, "%+e", offset); } if (flags & (int)SampleFlags::HAS_SEQUENCE) {