tiny.acp.reader
Defined in tiny.acp.
A reader splits a stream of bytes into lines at each newline, inside one buffer whose size the caller fixes in advance.
API (7)
Types and contracts
Public types and contracts.
Capacity: A caller learns the buffer size before any buffer exists, for example to set aside the reader's share of one larger region of memory.Exhaustion: A caller uses this error to tell an overlong line apart from other failures.Limits: A caller chooses the longest line the reader must accept, so the reader's buffer size follows.Poll: A caller's read loop switches on this result to handle a line, read more input, or stop.Status: A caller uses this snapshot to report how the reader is doing, or to explain why it stopped.Storage: A caller uses this type to read lines from a pipe or a file within a memory budget fixed in advance, as the client does with the agent's output.
Values and defaults
Public values and defaults.
default_limits: A line limit of 2 MiB (2 1024 1024 bytes) for callers with no size of their own.
Source
Source: lib/acp/src/reader/root.zig
zig
//! A reader splits a stream of bytes into lines at each newline, inside one buffer whose size the//! caller fixes in advance. The package's client reads the agent's output through it, and any//! program that reads newline-separated messages from a pipe can use it alone.//!//! Memory for input from another program has to stay bounded, and its size has to be known before//! that program starts.//!//! A line can arrive in pieces, one read can hold more than one line, the last line can lack its//! newline, and a line can be longer than any buffer set aside for it.//!//! The buffer holds the longest allowed line plus its newline, and `Storage.init` allocates it in//! one allocation. After `activate`, nothing the reader does allocates: the caller reads input into//! free space the reader hands out, and the reader returns each line as a slice of its buffer.//! Before it hands out free space, the reader moves the unread bytes to the front of the buffer//! (*compaction*), and a line returned earlier stops being valid then. A line longer than the limit//! stops the reader for good (*terminal*), before any caller parses it, and every later poll fails//! with `error.ReaderMessageCapacityExceeded`. The reader keeps counters a caller can read for the//! lines rejected and the bytes waiting, and a caller reads the longest line seen (*high-water//! mark*). The reader states the buffer's size formula and what the buffer leaves out in a//! compile-time record (*capacity claim*), and that record names a test for each promise it makes.//! `default_limits` sets the line limit to 2 MiB for callers with no size of their own.const capacity = @import("capacity.zig");const storage = @import("storage.zig");/// A line limit of 2 MiB (2 * 1024 * 1024 bytes) for callers with no size of their own. The package/// exports it as `acp.default_reader_limits`, and the README's example passes it to the client.pub const default_limits: Limits = .{ .message_bytes = 2 * 1024 * 1024 };pub const Capacity = capacity.Capacity;pub const Exhaustion = storage.Exhaustion;pub const Limits = capacity.Limits;pub const Poll = storage.Poll;pub const Status = storage.Status;pub const Storage = storage.Storage;Source: lib/acp/src/root.zig:64
zig
pub const reader = @import("reader/root.zig");Audit
| Definitions | 1 |
|---|---|
| Public names | 1 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |