# `ExWapp.Binary`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/binary.ex#L1)

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.

# `binary_node`

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

# `decode`

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

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

# `decode!`

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

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

# `encode`

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

Encodes a node into WhatsApp's binary node format.

# `encode!`

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

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

# `raw`

```elixir
@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`

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

---

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