1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

io: pass instance pointer everywhere

This commit is contained in:
Steffen Vogel 2018-05-12 18:01:48 +02:00
parent 011971920d
commit 221937bb5e
12 changed files with 96 additions and 93 deletions

View file

@ -90,10 +90,10 @@ struct format_type {
*/
/** @see format_type_sscan */
int (*sscan)(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
int (*sscan)(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt);
/** @see format_type_sprint */
int (*sprint)(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
int (*sprint)(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt);
/** @} */

View file

@ -27,10 +27,10 @@
/* Forward declarations */
struct sample;
int json_pack_sample(json_t **j, struct sample *s, int flags);
int json_pack_sample(struct io *io, json_t **j, struct sample *s);
int json_unpack_sample(json_t *j, struct sample *s, int flags);
int json_unpack_sample(struct io *io, json_t *j, struct sample *s);
int json_fprint(FILE *f, struct sample *smps[], unsigned cnt, int flags);
int json_fprint(struct io *io, FILE *f, struct sample *smps[], unsigned cnt);
int json_fscan(FILE *f, struct sample *smps[], unsigned cnt, int flags);
int json_fscan(struct io *io, FILE *f, struct sample *smps[], unsigned cnt);

View file

@ -29,7 +29,7 @@
struct sample;
/** Copy / read struct msg's from buffer \p buf to / fram samples \p smps. */
int protobuf_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt);
/** Read struct sample's from buffer \p buf into samples \p smps. */
int protobuf_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
int protobuf_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt);

View file

@ -54,7 +54,7 @@ enum raw_flags {
};
/** Copy / read struct msg's from buffer \p buf to / fram samples \p smps. */
int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
int raw_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt);
/** Read struct sample's from buffer \p buf into samples \p smps. */
int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
int raw_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt);

View file

@ -35,7 +35,7 @@ enum villas_binary_flags {
};
/** Copy / read struct msg's from buffer \p buf to / fram samples \p smps. */
int villas_binary_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags);
int villas_binary_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt);
/** Read struct sample's from buffer \p buf into samples \p smps. */
int villas_binary_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags);
int villas_binary_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt);

View file

@ -30,21 +30,21 @@
#include <villas/sample.h>
#include <villas/timing.h>
size_t csv_sprint_single(char *buf, size_t len, struct sample *s, int flags)
size_t csv_sprint_single(struct io *io, char *buf, size_t len, struct sample *s)
{
size_t off = 0;
if (flags & SAMPLE_HAS_ORIGIN)
if (io->flags & SAMPLE_HAS_ORIGIN)
off += snprintf(buf + off, len - off, "%ld%c%09ld", s->ts.origin.tv_sec, CSV_SEPARATOR, s->ts.origin.tv_nsec);
else
off += snprintf(buf + off, len - off, "nan%cnan", CSV_SEPARATOR);
if (flags & SAMPLE_HAS_RECEIVED)
if (io->flags & SAMPLE_HAS_RECEIVED)
off += snprintf(buf + off, len - off, "%c%f", CSV_SEPARATOR, time_delta(&s->ts.origin, &s->ts.received));
else
off += snprintf(buf + off, len - off, "%cnan", CSV_SEPARATOR);
if (flags & SAMPLE_HAS_SEQUENCE)
if (io->flags & SAMPLE_HAS_SEQUENCE)
off += snprintf(buf + off, len - off, "%c%u", CSV_SEPARATOR, s->sequence);
else
off += snprintf(buf + off, len - off, "%cnan", CSV_SEPARATOR);
@ -65,7 +65,7 @@ size_t csv_sprint_single(char *buf, size_t len, struct sample *s, int flags)
return off;
}
size_t csv_sscan_single(const char *buf, size_t len, struct sample *s, int flags)
size_t csv_sscan_single(struct io *io, const char *buf, size_t len, struct sample *s)
{
const char *ptr = buf;
char *end;
@ -127,13 +127,13 @@ out: if (*end == '\n')
return end - buf;
}
int csv_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int csv_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int i;
size_t off = 0;
for (i = 0; i < cnt && off < len; i++)
off += csv_sprint_single(buf + off, len - off, smps[i], flags);
off += csv_sprint_single(io, buf + off, len - off, smps[i]);
if (wbytes)
*wbytes = off;
@ -141,13 +141,13 @@ int csv_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
return i;
}
int csv_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int csv_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
int i;
size_t off = 0;
for (i = 0; i < cnt && off < len; i++)
off += csv_sscan_single(buf + off, len - off, smps[i], flags);
off += csv_sscan_single(io, buf + off, len - off, smps[i]);
if (rbytes)
*rbytes = off;

View file

@ -69,20 +69,20 @@ static int json_unpack_timestamps(json_t *json_ts, struct sample *smp)
return 0;
}
int json_pack_sample(json_t **j, struct sample *smp, int flags)
int json_pack_sample(struct io *io, json_t **j, struct sample *smp)
{
json_t *json_smp;
json_error_t err;
json_smp = json_pack_ex(&err, 0, "{ s: o }", "ts", json_pack_timestamps(smp));
if (flags & SAMPLE_HAS_SEQUENCE) {
if (smp->flags & SAMPLE_HAS_SEQUENCE) {
json_t *json_sequence = json_integer(smp->sequence);
json_object_set(json_smp, "sequence", json_sequence);
}
if (flags & SAMPLE_HAS_VALUES) {
if (smp->flags & SAMPLE_HAS_VALUES) {
json_t *json_data = json_array();
for (int i = 0; i < smp->length; i++) {
@ -101,7 +101,7 @@ int json_pack_sample(json_t **j, struct sample *smp, int flags)
return 0;
}
int json_pack_samples(json_t **j, struct sample *smps[], unsigned cnt, int flags)
int json_pack_samples(struct io *io, json_t **j, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json_smps = json_array();
@ -109,7 +109,7 @@ int json_pack_samples(json_t **j, struct sample *smps[], unsigned cnt, int flags
for (int i = 0; i < cnt; i++) {
json_t *json_smp;
ret = json_pack_sample(&json_smp, smps[i], flags);
ret = json_pack_sample(io, &json_smp, smps[i]);
if (ret)
break;
@ -121,7 +121,7 @@ int json_pack_samples(json_t **j, struct sample *smps[], unsigned cnt, int flags
return cnt;
}
int json_unpack_sample(json_t *json_smp, struct sample *smp, int flags)
int json_unpack_sample(struct io *io, json_t *json_smp, struct sample *smp)
{
int ret;
json_error_t err;
@ -181,7 +181,7 @@ int json_unpack_sample(json_t *json_smp, struct sample *smp, int flags)
return 0;
}
int json_unpack_samples(json_t *json_smps, struct sample *smps[], unsigned cnt, int flags)
int json_unpack_samples(struct io *io, json_t *json_smps, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json_smp;
@ -194,7 +194,7 @@ int json_unpack_samples(json_t *json_smps, struct sample *smps[], unsigned cnt,
if (i >= cnt)
break;
ret = json_unpack_sample(json_smp, smps[i], flags);
ret = json_unpack_sample(io, json_smp, smps[i]);
if (ret < 0)
break;
}
@ -202,13 +202,13 @@ int json_unpack_samples(json_t *json_smps, struct sample *smps[], unsigned cnt,
return i;
}
int json_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int json_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json;
size_t wr;
ret = json_pack_samples(&json, smps, cnt, flags);
ret = json_pack_samples(io, &json, smps, cnt);
if (ret < 0)
return ret;
@ -222,7 +222,7 @@ int json_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], un
return ret;
}
int json_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int json_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json;
@ -232,7 +232,7 @@ int json_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], uns
if (!json)
return -1;
ret = json_unpack_samples(json, smps, cnt, flags);
ret = json_unpack_samples(io, json, smps, cnt);
json_decref(json);
@ -253,7 +253,7 @@ int json_print(struct io *io, struct sample *smps[], unsigned cnt)
FILE *f = io_stream_output(io);
for (i = 0; i < cnt; i++) {
ret = json_pack_sample(&json, smps[i], io->flags);
ret = json_pack_sample(io, &json, smps[i]);
if (ret)
return ret;
@ -279,7 +279,7 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
if (!json)
break;
ret = json_unpack_sample(json, smps[i], io->flags);
ret = json_unpack_sample(io, json, smps[i]);
if (ret)
goto skip;

View file

@ -29,7 +29,7 @@
#include <villas/io.h>
#include <villas/formats/json.h>
int json_reserve_pack_sample(json_t **j, struct sample *smp, int flags)
int json_reserve_pack_sample(struct io *io, json_t **j, struct sample *smp)
{
json_error_t err;
json_t *json_data, *json_name, *json_unit, *json_value;
@ -95,7 +95,7 @@ int json_reserve_pack_sample(json_t **j, struct sample *smp, int flags)
return 0;
}
int json_reserve_unpack_sample(json_t *json_smp, struct sample *smp, int flags)
int json_reserve_unpack_sample(struct io *io, json_t *json_smp, struct sample *smp)
{
int ret, idx;
double created = -1;
@ -162,7 +162,7 @@ int json_reserve_unpack_sample(json_t *json_smp, struct sample *smp, int flags)
* Note: The following functions are the same as io/json.c !!!
*/
int json_reserve_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int json_reserve_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json;
@ -170,7 +170,7 @@ int json_reserve_sprint(char *buf, size_t len, size_t *wbytes, struct sample *sm
assert(cnt == 1);
ret = json_reserve_pack_sample(&json, smps[0], flags);
ret = json_reserve_pack_sample(io, &json, smps[0]);
if (ret < 0)
return ret;
@ -184,7 +184,7 @@ int json_reserve_sprint(char *buf, size_t len, size_t *wbytes, struct sample *sm
return ret;
}
int json_reserve_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int json_reserve_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
int ret;
json_t *json;
@ -196,7 +196,7 @@ int json_reserve_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smp
if (!json)
return -1;
ret = json_reserve_unpack_sample(json, smps[0], flags);
ret = json_reserve_unpack_sample(io, json, smps[0]);
json_decref(json);
@ -217,7 +217,7 @@ int json_reserve_print(struct io *io, struct sample *smps[], unsigned cnt)
FILE *f = io_stream_output(io);
for (i = 0; i < cnt; i++) {
ret = json_reserve_pack_sample(&json, smps[i], io->flags);
ret = json_reserve_pack_sample(io, &json, smps[i]);
if (ret)
return ret;
@ -243,7 +243,7 @@ skip: json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
if (!json)
break;
ret = json_reserve_unpack_sample(json, smps[i], io->flags);
ret = json_reserve_unpack_sample(io, json, smps[i]);
if (ret)
goto skip;

View file

@ -27,7 +27,7 @@
#include <villas/plugin.h>
#include <villas/formats/protobuf.h>
int protobuf_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
unsigned psz;
@ -93,7 +93,7 @@ out:
return -1;
}
int protobuf_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int protobuf_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
unsigned i, j;
Villas__Node__Message *pb_msg;

View file

@ -23,6 +23,7 @@
#include <villas/sample.h>
#include <villas/plugin.h>
#include <villas/utils.h>
#include <villas/io.h>
#include <villas/formats/raw.h>
#include <villas/compat.h>
@ -56,7 +57,7 @@
/** Convert integer of varying width to big/little endian byte order */
#define SWAP_INT_TOE(o, b, n) (o ? htobe ## b (n) : htole ## b (n))
int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int raw_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int i, o = 0;
@ -69,25 +70,25 @@ int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
float *f32 = (void *) buf;
double *f64 = (void *) buf;
int bits = 1 << (flags >> 24);
int bits = 1 << (io->flags >> 24);
for (i = 0; i < cnt; i++) {
nlen = (smps[i]->length + o + (flags & RAW_FAKE) ? 3 : 0) * (bits / 8);
nlen = (smps[i]->length + o + (io->flags & RAW_FAKE) ? 3 : 0) * (bits / 8);
if (nlen >= len)
break;
/* First three values are sequence, seconds and nano-seconds timestamps */
if (flags & RAW_FAKE) {
if (io->flags & RAW_FAKE) {
switch (bits) {
case 32:
i32[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 32, smps[i]->sequence);
i32[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 32, smps[i]->ts.origin.tv_sec);
i32[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 32, smps[i]->ts.origin.tv_nsec);
i32[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 32, smps[i]->sequence);
i32[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 32, smps[i]->ts.origin.tv_sec);
i32[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 32, smps[i]->ts.origin.tv_nsec);
break;
case 64:
i64[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 64, smps[i]->sequence);
i64[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 64, smps[i]->ts.origin.tv_sec);
i64[o++] = SWAP_INT_TOE(flags & RAW_BE_HDR, 64, smps[i]->ts.origin.tv_nsec);
i64[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 64, smps[i]->sequence);
i64[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 64, smps[i]->ts.origin.tv_sec);
i64[o++] = SWAP_INT_TOE(io->flags & RAW_BE_HDR, 64, smps[i]->ts.origin.tv_nsec);
break;
}
}
@ -103,9 +104,9 @@ int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
union { double f; uint64_t i; } val;
if (flags & RAW_AUTO)
if (io->flags & RAW_AUTO)
raw_fmt = smps[i]->format & (1 << i) ? RAW_FORMAT_INT : RAW_FORMAT_FLT;
else if (flags & RAW_FLT)
else if (io->flags & RAW_FLT)
raw_fmt = RAW_FORMAT_FLT;
else
raw_fmt = RAW_FORMAT_INT;
@ -121,8 +122,8 @@ int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
}
switch (bits) {
case 32: f32[o++] = SWAP_FLT_TOE(flags & RAW_BE_FLT, val.f); break;
case 64: f64[o++] = SWAP_DBL_TOE(flags & RAW_BE_FLT, val.f); break;
case 32: f32[o++] = SWAP_FLT_TOE(io->flags & RAW_BE_FLT, val.f); break;
case 64: f64[o++] = SWAP_DBL_TOE(io->flags & RAW_BE_FLT, val.f); break;
}
break;
@ -135,9 +136,9 @@ int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
switch (bits) {
case 8: i8 [o++] = val.i; break;
case 16: i16[o++] = SWAP_INT_TOE(flags & RAW_BE_INT, 16, val.i); break;
case 32: i32[o++] = SWAP_INT_TOE(flags & RAW_BE_INT, 32, val.i); break;
case 64: i64[o++] = SWAP_INT_TOE(flags & RAW_BE_INT, 64, val.i); break;
case 16: i16[o++] = SWAP_INT_TOE(io->flags & RAW_BE_INT, 16, val.i); break;
case 32: i32[o++] = SWAP_INT_TOE(io->flags & RAW_BE_INT, 32, val.i); break;
case 64: i64[o++] = SWAP_INT_TOE(io->flags & RAW_BE_INT, 64, val.i); break;
}
break;
}
@ -150,7 +151,7 @@ int raw_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], uns
return i;
}
int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int raw_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
/* The raw format can not encode multiple samples in one buffer
* as there is no support for framing. */
@ -163,11 +164,11 @@ int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsi
float *f32 = (void *) buf;
double *f64 = (void *) buf;
int off, bits = 1 << (flags >> 24);
int off, bits = 1 << (io->flags >> 24);
smp->length = len / (bits / 8);
if (flags & RAW_FAKE) {
if (io->flags & RAW_FAKE) {
off = 3;
if (smp->length < off) {
@ -179,15 +180,15 @@ int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsi
switch (bits) {
case 32:
smp->sequence = SWAP_INT_TOH(flags & RAW_BE_HDR, 32, i32[0]);
smp->ts.origin.tv_sec = SWAP_INT_TOH(flags & RAW_BE_HDR, 32, i32[1]);
smp->ts.origin.tv_nsec = SWAP_INT_TOH(flags & RAW_BE_HDR, 32, i32[2]);
smp->sequence = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 32, i32[0]);
smp->ts.origin.tv_sec = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 32, i32[1]);
smp->ts.origin.tv_nsec = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 32, i32[2]);
break;
case 64:
smp->sequence = SWAP_INT_TOH(flags & RAW_BE_HDR, 64, i64[0]);
smp->ts.origin.tv_sec = SWAP_INT_TOH(flags & RAW_BE_HDR, 64, i64[1]);
smp->ts.origin.tv_nsec = SWAP_INT_TOH(flags & RAW_BE_HDR, 64, i64[2]);
smp->sequence = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 64, i64[0]);
smp->ts.origin.tv_sec = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 64, i64[1]);
smp->ts.origin.tv_nsec = SWAP_INT_TOH(io->flags & RAW_BE_HDR, 64, i64[2]);
break;
}
@ -208,7 +209,7 @@ int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsi
}
for (int i = 0; i < smp->length; i++) {
enum sample_data_format smp_fmt = flags & RAW_FLT ? SAMPLE_DATA_FORMAT_FLOAT
enum sample_data_format smp_fmt = io->flags & RAW_FLT ? SAMPLE_DATA_FORMAT_FLOAT
: SAMPLE_DATA_FORMAT_INT;
sample_set_data_format(smp, i, smp_fmt);
@ -216,17 +217,17 @@ int raw_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsi
switch (smp_fmt) {
case SAMPLE_DATA_FORMAT_FLOAT:
switch (bits) {
case 32: smp->data[i].f = SWAP_FLT_TOH(flags & RAW_BE_FLT, f32[i+off]); break;
case 64: smp->data[i].f = SWAP_DBL_TOH(flags & RAW_BE_FLT, f64[i+off]); break;
case 32: smp->data[i].f = SWAP_FLT_TOH(io->flags & RAW_BE_FLT, f32[i+off]); break;
case 64: smp->data[i].f = SWAP_DBL_TOH(io->flags & RAW_BE_FLT, f64[i+off]); break;
}
break;
case SAMPLE_DATA_FORMAT_INT:
switch (bits) {
case 8: smp->data[i].i = i8[i]; break;
case 16: smp->data[i].i = (int16_t) SWAP_INT_TOH(flags & RAW_BE_INT, 16, i16[i+off]); break;
case 32: smp->data[i].i = (int32_t) SWAP_INT_TOH(flags & RAW_BE_INT, 32, i32[i+off]); break;
case 64: smp->data[i].i = (int64_t) SWAP_INT_TOH(flags & RAW_BE_INT, 64, i64[i+off]); break;
case 16: smp->data[i].i = (int16_t) SWAP_INT_TOH(io->flags & RAW_BE_INT, 16, i16[i+off]); break;
case 32: smp->data[i].i = (int32_t) SWAP_INT_TOH(io->flags & RAW_BE_INT, 32, i32[i+off]); break;
case 64: smp->data[i].i = (int64_t) SWAP_INT_TOH(io->flags & RAW_BE_INT, 64, i64[i+off]); break;
}
break;
}

View file

@ -22,6 +22,7 @@
#include <string.h>
#include <villas/io.h>
#include <villas/formats/villas_binary.h>
#include <villas/formats/msg.h>
#include <villas/formats/msg_format.h>
@ -29,7 +30,7 @@
#include <villas/utils.h>
#include <villas/plugin.h>
int villas_binary_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int villas_binary_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int ret, i = 0;
char *ptr = buf;
@ -45,7 +46,7 @@ int villas_binary_sprint(char *buf, size_t len, size_t *wbytes, struct sample *s
if (ret)
return ret;
if (flags & VILLAS_BINARY_WEB) {
if (io->flags & VILLAS_BINARY_WEB) {
/** @todo convert to little endian */
}
else
@ -60,7 +61,7 @@ int villas_binary_sprint(char *buf, size_t len, size_t *wbytes, struct sample *s
return i;
}
int villas_binary_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int villas_binary_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
int ret, i = 0, values;
char *ptr = buf;
@ -84,7 +85,7 @@ int villas_binary_sscan(char *buf, size_t len, size_t *rbytes, struct sample *sm
break;
}
values = (flags & VILLAS_BINARY_WEB) ? msg->length : ntohs(msg->length);
values = (io->flags & VILLAS_BINARY_WEB) ? msg->length : ntohs(msg->length);
/* Check if remainder of message is in buffer boundaries */
if (ptr + MSG_LEN(values) > buf + len) {
@ -92,8 +93,9 @@ int villas_binary_sscan(char *buf, size_t len, size_t *rbytes, struct sample *sm
break;
}
if (flags & VILLAS_BINARY_WEB)
;
if (io->flags & VILLAS_BINARY_WEB) {
/** @todo convert from little endian */
}
else
msg_ntoh(msg);

View file

@ -31,22 +31,22 @@
#include <villas/sample.h>
#include <villas/formats/villas_human.h>
size_t villas_human_sprint_single(char *buf, size_t len, struct sample *s, int flags)
size_t villas_human_sprint_single(struct io *io, char *buf, size_t len, struct sample *s)
{
size_t off = 0;
if (flags & SAMPLE_HAS_ORIGIN) {
if (io->flags & SAMPLE_HAS_ORIGIN) {
off += snprintf(buf + off, len - off, "%llu", (unsigned long long) s->ts.origin.tv_sec);
off += snprintf(buf + off, len - off, ".%09llu", (unsigned long long) s->ts.origin.tv_nsec);
}
if (flags & SAMPLE_HAS_RECEIVED)
if (io->flags & SAMPLE_HAS_RECEIVED)
off += snprintf(buf + off, len - off, "%+e", time_delta(&s->ts.origin, &s->ts.received));
if (flags & SAMPLE_HAS_SEQUENCE)
if (io->flags & SAMPLE_HAS_SEQUENCE)
off += snprintf(buf + off, len - off, "(%u)", s->sequence);
if (flags & SAMPLE_HAS_VALUES) {
if (io->flags & SAMPLE_HAS_VALUES) {
for (int i = 0; i < s->length; i++) {
switch (sample_get_data_format(s, i)) {
case SAMPLE_DATA_FORMAT_FLOAT:
@ -64,7 +64,7 @@ size_t villas_human_sprint_single(char *buf, size_t len, struct sample *s, int f
return off;
}
size_t villas_human_sscan_single(const char *buf, size_t len, struct sample *s, int flags)
size_t villas_human_sscan_single(struct io *io, const char *buf, size_t len, struct sample *s)
{
char *end;
const char *ptr = buf;
@ -158,13 +158,13 @@ size_t villas_human_sscan_single(const char *buf, size_t len, struct sample *s,
return end - buf;
}
int villas_human_sprint(char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt, int flags)
int villas_human_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt)
{
int i;
size_t off = 0;
for (i = 0; i < cnt && off < len; i++)
off += villas_human_sprint_single(buf + off, len - off, smps[i], flags);
off += villas_human_sprint_single(io, buf + off, len - off, smps[i]);
if (wbytes)
*wbytes = off;
@ -172,13 +172,13 @@ int villas_human_sprint(char *buf, size_t len, size_t *wbytes, struct sample *sm
return i;
}
int villas_human_sscan(char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt, int flags)
int villas_human_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt)
{
int i;
size_t off = 0;
for (i = 0; i < cnt && off < len; i++)
off += villas_human_sscan_single(buf + off, len - off, smps[i], flags);
off += villas_human_sscan_single(io, buf + off, len - off, smps[i]);
if (rbytes)
*rbytes = off;