Skip to main content

Module framing

Module framing 

Source
Expand description

4-byte little-endian length-prefix frame codec.

Every IPC message (handshake, JSON-RPC request, JSON-RPC response, batch array, shim header) travels as:

+--------+------------------------------------+
| len:u32|                body                |
+--------+------------------------------------+
  • len is little-endian, excludes the prefix itself, and must be <= MAX_FRAME_BYTES (64 MiB). Larger frames are rejected at the codec boundary with io::ErrorKind::InvalidData.
  • body is UTF-8 JSON; one complete JSON document per frame, no chunking, no streaming.
  • An EOF at a frame boundary (zero bytes read before the length prefix) is a clean disconnect and returns Ok(None).
  • An EOF inside a length prefix or body is an io::ErrorKind::UnexpectedEof — truncated frames are never silently swallowed (this is the Phase 8a iter-1 B3 fix).

Enums§

FrameError
Errors surfaced by the JSON-flavoured codec helpers in this module.

Constants§

MAX_FRAME_BYTES
Per-frame ceiling. Values above this limit are rejected at read_frame / write_frame boundaries. The bound is generous enough for Phase 8b’s largest expected MCP tool responses (subgraph exports on monorepo-scale graphs) without forcing the complexity of a chunked protocol.

Functions§

read_frame
Read a single framed blob.
read_frame_json
Read a framed JSON blob and decode into T. Returns Ok(None) on a clean frame-boundary EOF.
write_frame
Write a single framed blob. Returns io::ErrorKind::InvalidInput if body.len() > MAX_FRAME_BYTES.
write_frame_json
Write a typed value as a framed JSON blob.