March Docs

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

fnblob_to_json_objblob_to_json_obj(blob)#
fncell_to_json_objcell_to_json_obj(cell)#
fnjson_get_intjson_get_int(jv, key)#
fnjson_get_strjson_get_str(jv, key)#
fnnotebook_msgnotebook_msg(content, cells)#
fnoutput_msgoutput_msg(idx, stdout_text, blobs, error_opt, vars)#

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, None otherwise.
  • 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
fnunescape_jsonunescape_json(s)#