Protocol
protocol.march — JSON building and parsing helpers for the notebook wire protocol.
Building (fn): output_msg/5 : {"type":"output", ...} — includes optional blobs array notebook_msg/2 : {"type":"notebook", ...}
Parsing (fn): json_get_str/2 : extract a JSON string field from a parsed Json value json_get_int/2 : extract a JSON integer field from a parsed Json value
Internal helpers (pfn/fn): json_opt_str/1 : "null" or json_str(s) vars_to_json/1 : (name, value) list → JSON object string blobs_to_json/1 : List((mime, b64)) → JSON array string cells_to_json/1 : List(Cell) → JSON array string unescape_json/1 : single-pass JSON string unescape
Functions
Build an output WebSocket frame for cell idx.
stdout_text: clean cell stdout (blob sentinels already stripped).blobs: list of(mime, base64_data)pairs extracted from sentinels.error_opt:Some(msg)for runtime errors,Noneotherwise.vars:(name, value)pairs from variable extraction.
Examples
march> String.contains(Protocol.output_msg(0, "hi", [], None, []), "\"type\":\"output\"")
true
march> String.contains(Protocol.output_msg(0, "", [], None, []), "\"blobs\":[]")
true