WhatsApp binary node encoder/decoder (ported from whatsmeow).
The public API currently exposes helpers to turn structured nodes into the on-the-wire representation used by WhatsApp Web and to decode the payloads back to nodes.
Summary
Functions
Decodes a WhatsApp binary node payload back into a node struct.
Decodes a WhatsApp binary node payload back into a node struct. Raises on failure.
Encodes a node into WhatsApp's binary node format.
Encodes a node into WhatsApp's binary node format. Raises on failure.
Wraps a binary payload so that the encoder treats it as raw bytes instead of a UTF-8 string.
Unpacks a decrypted WebSocket payload.
Types
@type binary_node() :: %ExWapp.Binary.Node{ attrs: map(), content: nil | ExWapp.Binary.Raw.t() | binary() | [binary_node()], tag: String.t() }
Functions
@spec decode(binary()) :: {:ok, binary_node()} | {:error, any()}
Decodes a WhatsApp binary node payload back into a node struct.
@spec decode!(binary()) :: binary_node()
Decodes a WhatsApp binary node payload back into a node struct. Raises on failure.
@spec encode(binary_node() | tuple()) :: {:ok, binary()} | {:error, any()}
Encodes a node into WhatsApp's binary node format.
@spec encode!(binary_node() | tuple()) :: binary()
Encodes a node into WhatsApp's binary node format. Raises on failure.
@spec raw(binary()) :: ExWapp.Binary.Raw.t()
Wraps a binary payload so that the encoder treats it as raw bytes instead of a UTF-8 string.
Unpacks a decrypted WebSocket payload.
The first byte contains flags that describe the remaining payload. WhatsApp currently sets bit 1 to indicate that the data is zlib-compressed. We strip the flag byte and optionally inflate the rest before returning it.