BaileysEx.Protocol.BinaryNode (baileys_ex v0.1.0-alpha.8)

Copy Markdown View Source

Encoder and decoder for WhatsApp's WABinary wire format.

WABinary is a compact binary encoding of XMPP-style nodes. Each node has a tag (string), attributes (string key-value map), and optional content (binary data, child nodes, or a string). Strings are compressed via token dictionaries, nibble packing, hex packing, or JID-aware encoding.

The encoded format does NOT include a frame length prefix -- that is handled by the connection/Noise layer.

Summary

Functions

Return :ok when the node has no direct error child, otherwise return its parsed error metadata.

Return the first direct child node matching the given tag.

Return the raw bytes of a child node whose content is explicit binary payload data.

Return the UTF-8 string content of a child node.

Return all direct child nodes.

Return all direct child nodes matching the given tag.

Decode binary data into a BaileysEx.BinaryNode.

Encode a BaileysEx.BinaryNode to binary.

Functions

assert_error_free(node)

@spec assert_error_free(BaileysEx.BinaryNode.t()) ::
  :ok
  | {:error,
     %{code: integer() | nil, text: String.t(), node: BaileysEx.BinaryNode.t()}}

Return :ok when the node has no direct error child, otherwise return its parsed error metadata.

child(node, child_tag)

@spec child(BaileysEx.BinaryNode.t() | nil, String.t()) ::
  BaileysEx.BinaryNode.t() | nil

Return the first direct child node matching the given tag.

child_bytes(node, child_tag)

@spec child_bytes(BaileysEx.BinaryNode.t() | nil, String.t()) :: binary() | nil

Return the raw bytes of a child node whose content is explicit binary payload data.

child_string(node, child_tag)

@spec child_string(BaileysEx.BinaryNode.t() | nil, String.t()) :: String.t() | nil

Return the UTF-8 string content of a child node.

This accepts either explicit string content or raw bytes that can be interpreted as UTF-8, mirroring Baileys' helper behavior.

children(arg1)

@spec children(BaileysEx.BinaryNode.t() | nil) :: [BaileysEx.BinaryNode.t()]

Return all direct child nodes.

children(node, child_tag)

@spec children(BaileysEx.BinaryNode.t() | nil, String.t()) :: [
  BaileysEx.BinaryNode.t()
]

Return all direct child nodes matching the given tag.

decode(data)

@spec decode(binary()) :: {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Decode binary data into a BaileysEx.BinaryNode.

Expects the raw encoded data (with the leading compression flag byte). Handles decompression if the compression bit is set.

encode(node)

@spec encode(BaileysEx.BinaryNode.t()) :: binary()

Encode a BaileysEx.BinaryNode to binary.

The output does not include a frame length prefix. The first byte is always 0 (no compression flag), followed by the encoded node.