# `ToonEx.Btoon.Phoenix.Serializer`
[🔗](https://github.com/ohhi-vn/toon_ex/blob/v1.6.0/lib/toon_ex/btoon/phoenix/serializer.ex#L1)

Satisfies the `PhoenixClient` JSON-parser contract, which requires
`encode/2`, `encode!/2`, `decode/2`, `decode!/2` and `encode_to_iodata!`.  The
optional `opts` argument is accepted but intentionally ignored so that this
module can be dropped in wherever a standard JSON library is expected.

This is the BTOON binary variant of `ToonEx.Phoenix.Serializer`. Instead of
emitting TOON text frames, messages/replies/broadcasts with map payloads are
encoded with the compact BTOON binary format, while `{:binary, data}` payloads
use the same dedicated length-prefixed binary frame protocol.

## Binary Frame Support

Binary frames use a length-prefixed binary protocol inherited from the TOON
serializer, so the same binary fast-path framing is supported. Map payloads
are BTOON-encoded rather than TOON-text-encoded.

## Text (BTOON) Frames

Map payloads are serialized with `Btoon.encode_to_iodata!/1` (BTOON binary),
and `decode!/2` with `opcode: :binary` decodes them back as required by
Phoenix WebSockets. The `:btoon` opcode is also accepted for direct use in
applications and tests.

This serializer is BTOON-only: incoming `:text` frames must carry a BTOON
payload starting with the `"BTON"` magic. Anything else raises `ArgumentError`.
Use `ToonEx.Phoenix.Serializer` for TOON text frames.

Note: This is a workaround to avoid adding a Phoenix library dependency.

# `decode!`

# `decode_btoon`

# `decode_text`

# `encode!`

# `fastlane!`

---

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