Do you know what I could use right now? A buffered output channel that flushes only when explicitly flushed by the program. Does #OCaml have this? I.e. out_channels that don't get full.
In general, this function is "read one whole message from the transit buffer":
val read_msg : Buffer.t -> msg option