34namespace neograph::async {
42struct SseParserOptions {
43 std::size_t max_partial_line_bytes = 64u * 1024u;
44 std::size_t max_event_bytes = 1u * 1024u * 1024u;
45 std::size_t max_pending_events = 1024u;
46 std::size_t max_pending_bytes = 8u * 1024u * 1024u;
49class NEOGRAPH_API SseEventParser {
52 explicit SseEventParser(SseParserOptions options = {});
58 void feed(std::string_view bytes);
62 std::vector<SseEvent> drain();
65 const std::string& last_event_id() const noexcept {
return last_id_; }
68 std::optional<std::uint64_t> retry_ms() const noexcept {
return retry_ms_; }
71 void reset() noexcept;
74 void consume_line(std::string_view line);
76 void ensure_can_add(std::
size_t current, std::
size_t addition,
77 std::
size_t limit, const
char* message);
78 [[noreturn]]
void fail_limit(const
char* message);
80 SseParserOptions options_;
82 std::
string cur_data_;
83 std::
string cur_event_;
85 std::optional<std::uint64_t> retry_ms_;
86 std::
size_t cur_event_bytes_ = 0;
87 bool cur_has_data_ = false;
88 bool skip_lf_ = false;
89 bool at_start_ = true;
90 std::vector<SseEvent> pending_;
91 std::
size_t pending_bytes_ = 0;
NEOGRAPH_API export/import macro for shared-library builds.