ExWapp.Binary (ExWapp v0.1.2)

Copy Markdown View Source

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

binary_node()

@type binary_node() :: %ExWapp.Binary.Node{
  attrs: map(),
  content: nil | ExWapp.Binary.Raw.t() | binary() | [binary_node()],
  tag: String.t()
}

Functions

decode(payload)

@spec decode(binary()) :: {:ok, binary_node()} | {:error, any()}

Decodes a WhatsApp binary node payload back into a node struct.

decode!(payload)

@spec decode!(binary()) :: binary_node()

Decodes a WhatsApp binary node payload back into a node struct. Raises on failure.

encode(node)

@spec encode(binary_node() | tuple()) :: {:ok, binary()} | {:error, any()}

Encodes a node into WhatsApp's binary node format.

encode!(node)

@spec encode!(binary_node() | tuple()) :: binary()

Encodes a node into WhatsApp's binary node format. Raises on failure.

raw(data)

@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.

unpack(arg1)

@spec unpack(binary()) :: {:ok, binary()} | {:error, term()}

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.