hyperlane-plugin-sse 23.0.0

A Server-Sent Events (SSE) streaming and topic pub/sub plugin for the Hyperlane framework with Last-Event-ID replay, heartbeat, and CRLF-safe event framing.
Documentation
/// Default SSE `Content-Type` header value with UTF-8 charset.
pub const SSE_CONTENT_TYPE: &str = "text/event-stream; charset=utf-8";

/// Default `Cache-Control` directive for SSE streams.
pub const SSE_CACHE_CONTROL: &str = "no-cache";

/// Reverse-proxy buffering disable header name for SSE streams.
pub const SSE_ACCEL_BUFFERING_HEADER: &str = "x-accel-buffering";

/// Reverse-proxy buffering disable header value for SSE streams.
pub const SSE_ACCEL_BUFFERING_VALUE: &str = "no";

/// Default heartbeat interval in milliseconds.
pub const DEFAULT_SSE_HEARTBEAT_MS: u64 = 15_000;

/// Default client reconnect retry hint in milliseconds.
pub const DEFAULT_SSE_RETRY_MS: u64 = 3_000;

/// Default bounded replay history retained per topic for `Last-Event-ID` resume.
pub const DEFAULT_SSE_REPLAY_CAPACITY: usize = 64;

/// Default broadcast channel capacity per topic.
pub const DEFAULT_SSE_CHANNEL_CAPACITY: usize = 256;

/// Default maximum number of active topics allowed in one [`SseHub`](crate::SseHub).
pub const DEFAULT_SSE_MAX_TOPICS: usize = 1024;

/// Number of lock-striped topic shards inside [`crate::SseHub`].
pub(crate) const SSE_SHARD_COUNT: usize = 64;

/// SSE `id` field prefix.
pub(crate) const SSE_FIELD_ID: &str = "id: ";

/// SSE `event` field prefix.
pub(crate) const SSE_FIELD_EVENT: &str = "event: ";

/// SSE `retry` field prefix.
pub(crate) const SSE_FIELD_RETRY: &str = "retry: ";

/// SSE `data` field prefix.
pub(crate) const SSE_FIELD_DATA: &str = "data: ";

/// SSE comment line prefix.
pub(crate) const SSE_COMMENT_PREFIX: &str = ": ";

/// Default heartbeat comment payload.
pub(crate) const SSE_HEARTBEAT_COMMENT: &str = "keep-alive";

/// Pre-encoded static SSE keep-alive heartbeat wire frame.
pub(crate) const SSE_HEARTBEAT_FRAME: &[u8] = b": keep-alive\n\n";

/// Maximum decimal digit length of an unsigned 64-bit integer.
pub(crate) const U64_DECIMAL_BUF_LEN: usize = 20;

/// Error display text when an [`SseHub`](crate::SseHub) reaches its topic limit.
pub(crate) const ERR_TOPIC_LIMIT: &str = "SSE topic limit reached";

/// Error display text when a topic broadcast channel has closed.
pub(crate) const ERR_CHANNEL_CLOSED: &str = "SSE topic channel closed";

/// Multiplicative 64-bit mixing constant for zero-allocation [`FxHasher`].
pub(crate) const FX_HASH_K: u64 = 0x517c_c1b7_2722_0a95;

/// SWAR per-byte low-bit mask (`0x01` replicated across 8 bytes).
pub(crate) const SWAR_LO_ONES: u64 = 0x0101_0101_0101_0101;

/// SWAR per-byte high-bit mask (`0x80` replicated across 8 bytes).
pub(crate) const SWAR_HI_BITS: u64 = 0x8080_8080_8080_8080;

/// SWAR replicated `\r` byte (`0x0D`) across 8 lanes.
pub(crate) const SWAR_CR_MASK: u64 = 0x0D0D_0D0D_0D0D_0D0D;

/// SWAR replicated `\n` byte (`0x0A`) across 8 lanes.
pub(crate) const SWAR_LF_MASK: u64 = 0x0A0A_0A0A_0A0A_0A0A;

/// ASCII line-feed byte (`\n`).
pub(crate) const BYTE_LF: u8 = b'\n';

/// ASCII carriage-return byte (`\r`).
pub(crate) const BYTE_CR: u8 = b'\r';

/// ASCII zero digit byte (`'0'`).
pub(crate) const BYTE_ZERO: u8 = b'0';

/// Stack buffer capacity in bytes for zero-allocation [`SseStream::send_event`].
pub(crate) const SSE_EVENT_STACK_CAP: usize = 512;

/// Stack buffer capacity in bytes for zero-allocation [`SseStream::send_comment`].
pub(crate) const SSE_COMMENT_STACK_CAP: usize = 256;

/// Stack buffer capacity in bytes for the initial SSE reconnect retry hint frame.
pub(crate) const SSE_RETRY_HINT_STACK_CAP: usize = 64;

/// Maximum bytes coalesced per single wire send in [`SseStream::serve_subscription`].
pub(crate) const SSE_COALESCE_MAX_BYTES: usize = 32 * 1024;

/// Two-digit ASCII decimal lookup pairs for `00..=99`.
pub(crate) const DEC_DIGITS_LUT: &[u8; 200] = b"00010203040506070809\
10111213141516171819\
20212223242526272829\
30313233343536373839\
40414243444546474849\
50515253545556575859\
60616263646566676869\
70717273747576777879\
80818283848586878889\
90919293949596979899";

/// Static zero string for decimal formatting fast path.
pub(crate) const ZERO_STR: &str = "0";