def stdio.chunked

ezmcp@0.1.0.0 · src/io.bend:332

import ezmcp@0.1.0.0/src/io.bend as Io
import Base
import emerging-ezjson@1.2.0.0/src/value.bend as Value
import ezmcp@0.1.0.0/src/rpc.bend as Rpc
import ezmcp@0.1.0.0/src/server.bend as Server
import ezmcp@0.1.0.0/src/line.bend as Line

332# after a read: an empty one is the end of stdin, and the bytes after the
333# last newline are the last message; any other is cut into lines
334def stdio.chunked(
335  ~C: Data,
336  ~run: C -> String -> Value.Json -> IO(Rpc.Out),
337  ~srv: Server.Server,
338  +ctx: C,
339  rev: String,
340  buf: List<&2, U32>,
341  bytes: List<&2, U32>,
342  again: List<&2, U32> -> String -> IO(Unit),
343  empty: Bool
344) -> IO(Unit):
345  match empty:
346    case True{}:
347      IO.bind(String, Unit, stdio.lines(C, run, srv, ctx, [buf], rev),
348        _r => IO.pure(Unit, Unit{}))
349    case False{}:
350      stdio.cut(C, run, srv, ctx, rev, again,
351        Line.cut(List.append(&2, U32, buf, bytes)))

Uses (15)

Used by (1)