boolean-value

xod/json/boolean-value

Extracts a boolean from a JSON stream
boolean-value
@/boolean-value
Extracts a boolean from a JSON stream
IN1@/parsed-json-chunk
Parsed chunk of a JSON document
IN2pulse
Process the incoming parsed chunk
boolean-value
IN1
IN2
OUT
DONE
DONEpulse
Pulses when a value is sucessfully extracted from parsed chunks
OUTboolean
Extracted value

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_IN2

nodespace {
    using ParserState = xod::json_parser::ParserState;
}

node {
    ParserState prevParsedState;

    void evaluate(Context ctx) {
        if (!isInputDirty<input_IN2>(ctx)) return;

        auto parsed = getValue<input_IN1>(ctx);

        if (parsed.state != prevParsedState) {
            if (prevParsedState == ParserState::IN_TRUE) {
                emitValue<output_OUT>(ctx, true);
                emitValue<output_DONE>(ctx, 1);
            } else if (prevParsedState == ParserState::IN_FALSE) {
                emitValue<output_OUT>(ctx, false);
                emitValue<output_DONE>(ctx, 1);
            }
        }

        prevParsedState = parsed.state;
    }
}