# `Raxol.Gateway.Adapter.Discord.Protocol`
[🔗](https://github.com/DROOdotFOO/raxol/blob/raxol_gateway-v0.2.0/lib/raxol/gateway/adapter/discord/protocol.ex#L1)

Pure codec for Discord Gateway v10 JSON frames.

Stateless: encodes the three client payloads the socket sends
(heartbeat, identify, resume) and classifies inbound frames into tagged
tuples. All connection state (sequence numbers, session ids, timers)
lives in `Raxol.Gateway.Adapter.Discord.GatewaySocket`.

Dispatch frames (op 0) are returned whole and string-keyed, exactly as
decoded, so the socket can hand them to its `:on_event` sink unmodified.

# `decoded`

```elixir
@type decoded() ::
  {:dispatch, map()}
  | {:hello, pos_integer()}
  | :heartbeat_request
  | :heartbeat_ack
  | :reconnect
  | {:invalid_session, resumable? :: boolean()}
  | {:unknown, term()}
  | {:error, term()}
```

# `decode`

```elixir
@spec decode(String.t()) :: decoded()
```

Classify one inbound text frame.

# `default_intents`

```elixir
@spec default_intents() :: pos_integer()
```

The default intent bitfield: GUILDS, GUILD_MESSAGES, DIRECT_MESSAGES,
and MESSAGE_CONTENT.

MESSAGE_CONTENT is privileged: it must also be enabled for the bot in
the Discord developer portal, or guild message content arrives empty.

# `encode_heartbeat`

```elixir
@spec encode_heartbeat(integer() | nil) :: String.t()
```

Encode a heartbeat (op 1) carrying the last seen sequence (or nil).

# `encode_identify`

```elixir
@spec encode_identify(String.t(), pos_integer()) :: String.t()
```

Encode an identify (op 2) with token and intents.

# `encode_resume`

```elixir
@spec encode_resume(String.t(), String.t(), integer()) :: String.t()
```

Encode a resume (op 6) for an interrupted session.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
