ssevents/decoder
Full-body and incremental SSE decoding.
Semantics chosen for the initial release:
- accepted line endings: LF and CRLF
- unknown fields are ignored
- EOF dispatches the final unterminated event or trailing comment
- the first decode error fails the whole operation
- retry values must be ASCII digits; values above
Limits.max_retry_valueare silently dropped toNone(symmetric withevent.retry_clamp/2) unlessLimits.strict_retry_capis set, in which case they fail withInvalidRetry(_)(#95)
Types
pub opaque type DecodeState
Values
pub fn decode(
input: String,
) -> Result(List(event.Item), error.SseError)
Decode a full SSE wire-format String into the list of Items it
represents.
Runs with limit.default(), whose per-event cap is
default_max_event_bytes (65_536 bytes). Any single event larger
than that fails the whole decode with Error(EventTooLarge(65_536))
— note this is asymmetric with the encoder, which never rejects an
event for sheer size. Callers that knowingly round-trip events
above 65_536 bytes (e.g. 100 KB JSON payloads emitted by their own
encoder) must raise the cap via
decode_with_limits(wire, limit.default() |> limit.with_max_event_size(200_000)). (#96)
pub fn decode_bytes(
input: BitArray,
) -> Result(List(event.Item), error.SseError)
BitArray counterpart of decode/1. Same default per-event cap of
65_536 bytes; reach for decode_bytes_with_limits with
limit.with_max_event_size/2 to raise it. (#96)
pub fn decode_bytes_with_limits(
input: BitArray,
limits limits: limit.Limits,
) -> Result(List(event.Item), error.SseError)
pub fn decode_with_limits(
input: String,
limits limits: limit.Limits,
) -> Result(List(event.Item), error.SseError)
pub fn finish(
state: DecodeState,
) -> Result(List(event.Item), error.SseError)
pub fn new_decoder() -> DecodeState
pub fn new_decoder_with_limits(
limits: limit.Limits,
) -> DecodeState
pub fn push(
state: DecodeState,
chunk: BitArray,
) -> Result(#(DecodeState, List(event.Item)), error.SseError)