+ switch (packet->type) {
+ case SR_DF_LOGIC:
+ logic = packet->payload;
+ if (ctx->header) {
+ /*
+ * First data packet: prime the output with the
+ * previously prepared header.
+ */
+ *out = ctx->header;
+ ctx->header = NULL;
+ } else {
+ *out = g_string_sized_new(512);
+ }
+
+ for (i = 0; i <= logic->length - ctx->unitsize; i += ctx->unitsize) {
+ for (j = 0; j < ctx->num_enabled_probes; j++) {
+ p = logic->data + i + j / 8;
+ c = *p & (1 << (j % 8));
+ g_string_append_c(*out, c ? '1' : '0');
+ g_string_append_c(*out, ctx->separator);
+ }
+ if (j) {
+ /* Drop last separator. */
+ g_string_truncate(*out, (*out)->len - 1);
+ }
+ g_string_append_printf(*out, "\n");
+ }