ToonEx.Btoon.Phoenix.Serializer (toon_ex v1.3.1)

Copy Markdown View Source

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

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

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

Summary

Functions

decode!(raw_message, opts)

decode_btoon(raw_message)

encode!(reply)

fastlane!(msg)