WebSockex - An Elixir WebSocket client

It seems like websockex doesn’t support iodata in send_frame?

** (exit) exited in: WebSockex.call(Some.Client, {:text, ["{\"cmd\":", [34, [], "keepalive", 34], ",\"session_id\":", [34, [], 34], ",\"transaction\":", [34, [], "y653PDXvxmGaW+0y4Nab", 34], 125]})
    ** (EXIT) an exception was raised:
        ** (ArgumentError) argument error
            :erlang.byte_size(["{\"cmd\":", [34, [], "keepalive", 34], ",\"session_id\":", [34, [], 34], ",\"transaction\":", [34, [], "y653PDXvxmGaW+0y4Nab", 34], 125])
            (websockex) lib/websockex/frame.ex:296: WebSockex.Frame.get_payload_length_bin/1
            (websockex) lib/websockex/frame.ex:257: WebSockex.Frame.encode_frame/1
            (websockex) lib/websockex.ex:723: WebSockex.sync_send/5
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
    (websockex) lib/websockex.ex:349: WebSockex.send_frame/2

Wouldn’t it be easier to use IO.iodata_length instead of :erlang.byte_size? Since it works both on binaries and iolists.

iex(8)> data = API.Keepalive.new() |> Jason.encode_to_iodata!() |> IO.iodata_length()
74
iex(9)> data = API.Keepalive.new() |> Jason.encode!() |> IO.iodata_length()
74
1 Like