stdioChannel function
Creates a StreamChannel for Stdio communication where each message is a
map, encoded as JSON on its own line.
This expects incoming messages on input, and writes messages to output.
Frames which are not JSON objects are answered with JSON-RPC error
responses and never surface on the channel; see jsonRpcChannel.
Implementation
StreamChannel<Map<String, Object?>> stdioChannel({
required Stream<List<int>> input,
required StreamSink<List<int>> output,
}) => jsonRpcChannel(
StreamChannel.withCloseGuarantee(input, output)
.transform(StreamChannelTransformer.fromCodec(utf8))
.transformStream(const LineSplitter())
.transformSink(
StreamSinkTransformer.fromHandlers(
handleData: (data, sink) {
sink.add('$data\n');
},
),
),
);