-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
serializer.ex
29 lines (24 loc) · 974 Bytes
/
serializer.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
defmodule Phoenix.Socket.Serializer do
@moduledoc """
A behaviour that serializes incoming and outgoing socket messages.
By default Phoenix provides `Phoenix.Socket.V2.JSONSerializer` that
encodes to JSON and decodes JSON messages.
Custom serializers may be configured in the socket.
"""
@doc """
Encodes a `Phoenix.Socket.Broadcast` struct to fastlane format.
"""
@callback fastlane!(Phoenix.Socket.Broadcast.t()) ::
{:socket_push, :text, iodata()}
| {:socket_push, :binary, iodata()}
@doc """
Encodes `Phoenix.Socket.Message` and `Phoenix.Socket.Reply` structs to push format.
"""
@callback encode!(Phoenix.Socket.Message.t() | Phoenix.Socket.Reply.t()) ::
{:socket_push, :text, iodata()}
| {:socket_push, :binary, iodata()}
@doc """
Decodes iodata into `Phoenix.Socket.Message` struct.
"""
@callback decode!(iodata, options :: Keyword.t()) :: Phoenix.Socket.Message.t()
end