NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
sse_parser.h File Reference

Incremental Server-Sent Events parser (WHATWG HTML, "Server-sent events", event stream interpretation). More...

#include <neograph/api.h>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for sse_parser.h:

Go to the source code of this file.

Detailed Description

Incremental Server-Sent Events parser (WHATWG HTML, "Server-sent events", event stream interpretation).

Pure state machine: bytes in (feed), complete events out (drain). The caller pairs this with a transport that delivers byte chunks (typically async_post_stream), since one HTTP chunk may contain partial, whole, or multiple SSE events.

It follows the WHATWG processing rules, which MCP's Streamable HTTP transport and the official MCP SDKs rely on:

  • lines end with CRLF, LF or CR, also when a CRLF is split across feeds;
  • one leading UTF-8 byte order mark is skipped;
  • data lines join with LF, and an event with no data line is not dispatched;
  • id sets the last event ID (ignored when it contains NUL), which every later event carries until another id changes it;
  • retry with only ASCII digits sets the reconnection time;
  • lines starting with ':' are comments, unknown fields are ignored;
  • an event the stream ends in the middle of is never dispatched.

Definition in file sse_parser.h.