gaato/discord/gateway does not have a README file

    GatewayTransport

    pub(open) trait GatewayTransport {
    async fn recv(Self) -> GatewayFrame
    async fn send(Self, String) -> Unit
    async fn close(Self, code~ : Int) -> Unit
    }

    The seam between the shard driver and the network: implemented by the real WebSocket connection in production and by an in-memory fake in tests.

    Inflater

    pub(open) trait Inflater {
    fn push(Self, Bytes) -> String? raise
    }

    Stateful decoder seam for Gateway compression. Implementations retain one inflate context across messages. None means the Z_SYNC_FLUSH suffix has not arrived yet.

    InflateError

    pub(all) suberror InflateError {
    InflateError(status~ : Int)
    InvalidUtf8
    Unsupported
    } derive(
    Debug
    )

    Raised when a compressed Gateway stream cannot be initialized or decoded.

    TransportClosed

    pub(all) suberror TransportClosed {
    TransportClosed(code~ : Int?, reason~ : String)
    } derive(
    Debug
    )

    Raised by transports when the peer closed the connection. code is the WebSocket close code (Discord uses 4xxx application codes), None for abnormal/transport-level termination.

    CommandLimiter

    pub struct CommandLimiter {
    // private fields
    }

    Sliding-window log limiter for gateway commands: Discord allows 120 sends per 60 seconds per connection; a few slots are reserved for heartbeats (which bypass this limiter), so user commands default to 115.

    CommandLimiter::CommandLimiter

    fn CommandLimiter::CommandLimiter(limit? : Int, sleeper? : async (Int) -> Unit) -> CommandLimiter

    Create a limiter allowing limit sends per 60-second sliding window.

    CommandLimiter::acquire

    async fn CommandLimiter::acquire(self : CommandLimiter) -> Unit

    Wait until a send slot is available within the window, then consume it.

    GatewayFrame

    pub(all) enum GatewayFrame {
    Text(String)
    Binary(Bytes)
    } derive(
    Debug
    )

    A complete WebSocket message received from the Gateway.

    ReconnectPolicy

    pub(all) enum ReconnectPolicy {
    Resume
    Reidentify
    Fatal
    } derive(Eq,
    Debug
    )

    Action after a gateway close: resume the session, identify from scratch, or give up because reconnecting cannot succeed.

    Session

    pub(all) struct Session {
    id : String
    resume_url : String
    sequence : Int64
    } derive(ToJson,
    Debug
    ,
    FromJson
    )

    Gateway session state retained across reconnects for RESUME. Persist it (for example with to_json) and pass it to Shard::start(resume~) after a process restart. sequence serializes as a JSON string (core's Int64 encoding); from_json accepts that form.

    Session::to_json

    fn Session::to_json(Session) -> Json

    Shard

    pub struct Shard {
    // private fields
    }

    A single gateway connection with automatic heartbeat, resume, and reconnect. Pull events with next; the shard's tasks live in the task group passed to start, so cancelling the group tears the shard down.

    Shard::close

    async fn Shard::close(self : Shard) -> Unit noraise

    Request a graceful shutdown: closes the connection with code 1000 (which invalidates the session — Discord will not allow a resume after it).

    Shard::latency_ms

    fn Shard::latency_ms(self : Shard) -> Int64?

    Latest heartbeat round-trip time in milliseconds.

    Shard::next

    async fn Shard::next(self : Shard) -> ShardEvent

    Pull the next event. Blocks until one is available.

    Shard::send

    async fn Shard::send(self : Shard, command : Json) -> Unit

    Send a gateway command (presence update, request guild members, ...). Rate limited (120/60s minus heartbeat reserve) and serialized with the shard's other writes.

    Shard::session

    fn Shard::session(self : Shard) -> Session?

    A copy of the current gateway session, or None before the first READY and after the session was invalidated. Persist it to RESUME after a restart.

    Shard::start

    fn[X] Shard::start(group :
    TaskGroup
    [X], token~ : String, intents~ :
    Intents
    , capabilities? :
    GatewayCapabilities
    , gateway_url? : String, shard_id? : Int, shard_count? : Int, identify_queue? : &
    IdentifyQueue
    , event_filter? : (
    EventKind
    ) -> Bool, connector? : async (String) -> &GatewayTransport, compress? : Bool, inflater_factory? : () -> &Inflater raise, queue_capacity? : Int, telemetry? : (
    TelemetryEvent
    ) -> Unit, sleeper? : async (Int) -> Unit, rand? :
    Rand
    , resume? : Session) -> Shard

    Spawn a shard into group and return its handle. resume seeds the session so the first connection attempts RESUME at its resume_url.

    Shard::state

    fn Shard::state(self : Shard) -> ShardState

    The current lifecycle state of this shard.

    ShardEvent

    pub(all) enum ShardEvent {
    Dispatch(
    Event
    )
    Connected(resumed~ : Bool)
    Disconnected(code~ : Int?, resuming~ : Bool)
    FatallyClosed(code~ : Int)
    } derive(
    Debug
    )

    Events surfaced by Shard::next.

    ShardState

    pub(all) enum ShardState {
    Disconnected(reconnect_attempts~ : Int)
    Connecting
    Identifying
    Resuming
    Active
    FatallyClosed(code~ : Int)
    } derive(Eq,
    Debug
    )

    Shard lifecycle state.

    connect_websocket

    async fn connect_websocket(url : String) -> &GatewayTransport

    Connect to the gateway over WebSocket (the default connector).

    on_close

    fn on_close(code : Int?, has_session : Bool) -> ReconnectPolicy

    Classify a close code into the action to take, per the Discord docs.

    • fatal: authentication failure or invalid shard/intent configuration — reconnecting cannot succeed;
    • re-identify: the session is gone (invalid seq, session timeout);
    • resume: everything else (transient errors, unclean closes), provided a session exists.

    zlib_stream_supported

    fn zlib_stream_supported() -> Bool

    Whether this backend can inflate Discord's zlib-stream transport compression. True on native (zlib is loaded at runtime).