Skip to main content

MAX_BUFFER_SIZE

Constant MAX_BUFFER_SIZE 

Source
pub const MAX_BUFFER_SIZE: usize = _; // 1_048_576usize
Expand description

Maximum line size in bytes.

Important: BufRead::lines() uses read_line() under the hood. Without a per-line cap, read_line() can accumulate arbitrarily large Strings even if fill_buf() only ever returns small chunks.

The value of 1 MiB was chosen to:

  • Handle most legitimate JSON documents (typically < 100KB)
  • Allow for reasonably long single-line JSON outputs
  • Prevent memory exhaustion from malicious input
  • Keep the buffer size manageable for most systems

If your use case requires larger single-line JSON, consider:

  • Modifying your agent to output NDJSON (newline-delimited JSON)
  • Adjusting this constant and rebuilding