protoflow-blocks 0.4.3

Protoflow implements flow-based programming (FBP) for Rust using Protocol Buffers messages.
Documentation
// This is free and unencumbered software released into the public domain.

use bytes::Bytes;
use protoflow_blocks::{Const, IoBlocks, System, SystemBuilding, SystemExecution};
use protoflow_core::{runtimes::StdRuntime, transports::MpscTransport};

#[test]
fn json_roundtrip() -> Result<(), ()> {
    let mut system = System::new(&StdRuntime::new(MpscTransport::new()).unwrap());

    let input_bytes = Bytes::from(r#"[null,true,1,10.1,"hello!",{"1":false,"2":[1,2]}]"#);

    let input = system.block(Const::with_system(&system, input_bytes.clone()));
    let decode = system.decode_json();
    let encode = system.encode_json();
    let output = system.input();

    system.connect(&input.output, &decode.input);
    system.connect(&decode.output, &encode.input);
    system.connect(&encode.output, &output);

    let thread = std::thread::spawn(|| system.execute().unwrap().join().unwrap());

    let message = output.recv().unwrap().unwrap();

    thread.join().unwrap();

    assert_eq!(input_bytes, message);

    Ok(())
}