ExWapp.Transport.Frame (ExWapp v0.1.2)

Copy Markdown View Source

WhatsApp-specific websocket frame encoding.

Frames are encoded as a WA header (sent once per connection) followed by a 24-bit big-endian payload length and the raw payload bytes.

Summary

Functions

Consumes as many frames as possible from buffer.

Wraps the given payload in a WA websocket frame.

Returns the static WA connection header.

Functions

decode(buffer)

@spec decode(binary()) :: {[binary()], binary()}

Consumes as many frames as possible from buffer.

Returns {frames, rest} where frames is a list of payload binaries in FIFO order and rest is the leftover buffer that did not yet form a full frame.

encode(payload, opts \\ [])

@spec encode(
  binary(),
  keyword()
) :: binary()

Wraps the given payload in a WA websocket frame.

The :include_header option ensures the header is prefixed once per connection. Callers are expected to keep track of whether the header was already sent for a connection and set the option accordingly.

header()

@spec header() :: binary()

Returns the static WA connection header.