Behaviour for encoding/decoding Discord Gateway payloads.
Two implementations are provided:
EDA.Gateway.Encoding.ETF(default) — Erlang External Term Format. Binary encoding decoded natively by the BEAM via:erlang.binary_to_term/1. Payloads are ~15-30% smaller than JSON and decode significantly faster.EDA.Gateway.Encoding.JSON— JSON viaJason. Text-based, useful for debugging or when ETF is undesirable.
Configuration
config :eda, gateway_encoding: :etf # default
config :eda, gateway_encoding: :jsonInteraction with zlib
Both encodings work with zlib-stream compression. The gateway connection
decompresses frames before passing them to decode/1, so the encoding
module always receives raw (uncompressed) binary data.
Summary
Callbacks
Decodes a raw gateway payload binary into a map with string keys.
Encodes a map into a gateway payload ready to send over WebSocket.
Returns the encoding name for the gateway URL query parameter ("json" or "etf").
Callbacks
Decodes a raw gateway payload binary into a map with string keys.
Encodes a map into a gateway payload ready to send over WebSocket.
Returns {:text, binary()} for JSON or {:binary, binary()} for ETF,
matching the frame types expected by WebSockex.
@callback url_encoding() :: String.t()
Returns the encoding name for the gateway URL query parameter ("json" or "etf").
Functions
@spec module() :: module()
Returns the configured encoding module.
Reads :gateway_encoding from the :eda application config.
Defaults to EDA.Gateway.Encoding.ETF.