diff --git a/include/villas/msg.h b/include/villas/msg.h index 8379969f5..2fb032f8c 100644 --- a/include/villas/msg.h +++ b/include/villas/msg.h @@ -16,7 +16,7 @@ struct node; -/** Swaps message contents byte-order. +/** Swaps the byte order of the header part of struct msg. * * Message can either be transmitted in little or big endian * format. The actual endianess for a message is defined by the @@ -27,7 +27,7 @@ struct node; * * @param m A pointer to the message */ -void msg_swap(struct msg *m); +void msg_hdr_swap(struct msg *m); /** Check the consistency of a message. * diff --git a/lib/msg.c b/lib/msg.c index 704e348c2..70b277d31 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -22,15 +22,12 @@ #include "node.h" #include "utils.h" -void msg_swap(struct msg *m) +void msg_hdr_swap(struct msg *m) { m->length = bswap_16(m->length); m->sequence = bswap_32(m->sequence); m->ts.sec = bswap_32(m->ts.sec); m->ts.nsec = bswap_32(m->ts.nsec); - - for (int i = 0; i < m->length; i++) - m->data[i].i = bswap_32(m->data[i].i); m->endian ^= 1; } diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 265da681e..000fc123a 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -332,7 +332,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt) /* Convert message to host endianess */ if (hdr.endian != MSG_ENDIAN_HOST) - msg_swap(&hdr); + msg_hdr_swap(&hdr); samples = bytes / MSG_LEN(hdr.length); if (samples > cnt) { @@ -373,8 +373,12 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt) break; /* Convert message to host endianess */ - if (m->endian != MSG_ENDIAN_HOST) - msg_swap(m); + if (m->endian != MSG_ENDIAN_HOST) { + msg_hdr_swap(m); + + for (int i = 0; i < m->length; i++) + smp->data[i].i = bswap_32(smp->data[i].i); + } smp->length = m->length; smp->sequence = m->sequence;