pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::orch::SseParser Class Reference

Parses a text/event-stream body fed in chunks of any size, as the WHATWG HTML specification defines it. More...

#include <sse.hpp>

Public Types

using Handler = std::function< void(const SseEvent &)>
 

Public Member Functions

 SseParser (Handler on_event, std::size_t max_event_bytes=std::size_t{16}<< 20)
 
void feed (std::string_view chunk)
 Parses chunk, calling the handler for every event it completes.
 
void finish ()
 The end of the stream. An event without its closing blank line is discarded, as the specification requires.
 
std::optional< std::chrono::milliseconds > retry () const
 The reconnection time from the last valid retry: field, if any.
 

Detailed Description

Parses a text/event-stream body fed in chunks of any size, as the WHATWG HTML specification defines it.

Note
Lines may end in CRLF, LF or CR, also split across chunks. A leading byte-order mark, comment lines (:) and unknown fields are ignored. An event with no data isn't dispatched. Every event type is passed on: a provider dispatches on SseEvent::type and ignores the types it doesn't know, which APIs add without notice (ping, for one).

Member Typedef Documentation

◆ Handler

using pulsatrix::orch::SseParser::Handler = std::function<void(const SseEvent&)>

Constructor & Destructor Documentation

◆ SseParser()

pulsatrix::orch::SseParser::SseParser ( Handler  on_event,
std::size_t  max_event_bytes = std::size_t{16}<< 20 
)
explicit
Parameters
on_eventcalled for each complete event.
max_event_bytesthe largest event (or line) to accept from the server.

Member Function Documentation

◆ feed()

void pulsatrix::orch::SseParser::feed ( std::string_view  chunk)

Parses chunk, calling the handler for every event it completes.

Exceptions
std::length_errorif a line or an event passes max_event_bytes.

◆ finish()

void pulsatrix::orch::SseParser::finish ( )

The end of the stream. An event without its closing blank line is discarded, as the specification requires.

◆ retry()

std::optional< std::chrono::milliseconds > pulsatrix::orch::SseParser::retry ( ) const
inline

The reconnection time from the last valid retry: field, if any.


The documentation for this class was generated from the following file: