Remove switch in prv emit

This commit is contained in:
Rodrigo Arias 2023-03-21 10:09:46 +01:00 committed by Rodrigo Arias Mallo
parent b42fb4d2f3
commit 96cfd6247e

View File

@ -108,25 +108,20 @@ emit(struct prv *prv, struct prv_chan *rchan)
rchan->last_value_set = 1; rchan->last_value_set = 1;
} }
/* Assume null */
long val = 0; long val = 0;
switch (value.type) { if (likely(value.type == VALUE_INT64)) {
case VALUE_INT64:
val = value.i; val = value.i;
if (rchan->flags & PRV_NEXT) if (rchan->flags & PRV_NEXT)
val++; val++;
if (~rchan->flags & PRV_ZERO && val == 0) { if (~rchan->flags & PRV_ZERO && val == 0) {
err("forbidden value 0 in %s: %s\n", err("forbidden value 0 in channel %s: %s",
chan->name, chan->name, value_str(value));
value_str(value));
return -1; return -1;
} }
break; } else if (value.type != VALUE_NULL) {
case VALUE_NULL: err("in channel %s: only int64 and null supported, found %s",
val = 0;
break;
default:
err("chan_read %s only int64 and null supported: %s\n",
chan->name, value_str(value)); chan->name, value_str(value));
return -1; return -1;
} }
@ -135,7 +130,6 @@ emit(struct prv *prv, struct prv_chan *rchan)
dbg("written %s for chan %s", value_str(value), chan->name); dbg("written %s for chan %s", value_str(value), chan->name);
return 0; return 0;
} }