glyde/gateway/reassembly

Where one zlib-stream payload ends and the next begins: the buffer, the terminator, the bound and the reset. The inflate itself belongs to the adapter.

Stateless. The buffer is a BitArray the caller carries and hands back, and the one outcome that still holds bytes is the only one carrying any. A caller cannot keep a stale buffer beside a finished payload, because there is nowhere to keep it.

Types

What taking in one binary WebSocket message produced.

pub type Intake {
  Partial(buffer: BitArray)
  Payload(bytes: BitArray)
  Overflow(bytes: Int)
}

Constructors

  • Partial(buffer: BitArray)

    Not a whole payload yet. buffer is what to hold until the next message. Still proof of life: counting only complete payloads makes a big GUILD_CREATE a zombie.

  • Payload(bytes: BitArray)

    One complete payload, ready for the inflater. Nothing is held over.

  • Overflow(bytes: Int)

    Holding this message would have taken the buffer past max_bytes with no complete payload in it. The bytes are gone: they mean nothing without the inflate context.

Values

pub const empty: BitArray

The buffer a connection starts with. Cleared on every new connection, resume included: leftovers will not decode against a fresh zlib context.

pub fn ends_with_sync(bytes: BitArray) -> Bool

Whether these bytes end with the zlib-stream terminator. The backwards slice handles fewer than four bytes with no size arithmetic.

pub fn feed(
  buffer: BitArray,
  message message: BitArray,
  max_bytes max_bytes: Int,
) -> Intake

Take one whole binary WebSocket message and say what it completed.

message must be a reassembled message, not an RFC 6455 frame. Discord ends a payload on a message boundary, so a caller that fed frames would flush a truncated payload the first time one was split.

max_bytes bounds only what is held over between messages, so a payload that is complete on arrival is delivered however large it is. Bounding a single message is the transport’s job. Discord publishes no size; this one is ours.

pub const sync_suffix: BitArray

What Z_SYNC_FLUSH leaves at the end of every zlib-stream payload. Discord’s own example checks exactly these four bytes.

Search Document