Skip to main content

Crate sse_frame

Crate sse_frame 

Source
Expand description

§sse-frame

Streaming parser for Server-Sent Events as emitted by LLM APIs.

Push bytes; pull complete Event records. The parser holds a small line buffer and a per-event field buffer; it never copies the transport payload more than once.

Supports the fields specified in the SSE standard: event:, data:, id:, and retry:. Multiple data: lines in a single event are joined with \n per the spec. Lines starting with : are comments.

§Example

use sse_frame::Parser;
let mut p = Parser::new();
let frames = p.push(
    b"event: message\ndata: {\"x\":1}\n\ndata: line1\ndata: line2\n\n",
);
assert_eq!(frames.len(), 2);
assert_eq!(frames[0].event.as_deref(), Some("message"));
assert_eq!(frames[0].data, "{\"x\":1}");
assert_eq!(frames[1].data, "line1\nline2");

Structs§

Event
One SSE event.
Parser
Incremental SSE parser.