1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Incremental parser for Server-Sent Events (SSE) byte streams.
//!
//! The crate turns an ordered sequence of byte chunks into an ordered
//! sequence of [`Event`]s, following the WHATWG HTML "interpreting an event
//! stream" algorithm. It does no HTTP, no reconnection, and no MIME checking:
//! those belong to the client built on top of it.
//!
//! Two layers:
//!
//! - [`SseParser`] is the sans-IO core. Feed it bytes, drain events. Every
//! byte sequence is a valid stream, so `feed` has no error to return, and
//! the time spent is linear in the bytes fed whatever the chunking.
//! `tests/no_panic.rs` and the fuzz target cover arbitrary bytes and
//! chunkings, and `tests/perf_gate.rs` bounds the scan count.
//! - [`EventStream`] wraps any [`futures_core::Stream`] of byte chunks and
//! yields events. It depends on `futures-core` alone, so it runs on any
//! executor.
//!
//! ```
//! use sse_parse::SseParser;
//!
//! let mut parser = SseParser::new();
//! parser.feed(b"event: add\ndata: first\ndata: second\n\n");
//!
//! let event = parser.next_event().unwrap();
//! assert_eq!(event.event, "add");
//! assert_eq!(event.data, "first\nsecond");
//! assert!(parser.next_event().is_none());
//! ```
//!
//! # Conformance notes
//!
//! - Invalid UTF-8 is replaced with U+FFFD, as the Encoding Standard's UTF-8
//! decoder does. Parsing never reports an encoding error.
//! - A leading `EF BB BF` byte order mark is stripped exactly once, at stream
//! offset 0, even when it arrives one byte per chunk. Later BOM bytes are
//! content.
//! - The last event ID string is committed at every blank line, including
//! blocks that dispatch no event, so `id:`-only blocks still update
//! reconnection state.
//! - The reconnection time (`retry`) takes effect when the field is
//! processed, independent of any later dispatch.
//! - A carriage return at end of stream terminates its line.
//!
//! # `no_std`
//!
//! Disable the default `std` feature to build on `core + alloc`.
extern crate alloc;
pub use Event;
pub use ;
pub use ;