   end
 
   defp new_data(state, <<>>) do
-    %{state | tail: <<>>}
+    state
   end
 
   defp new_data(state, data) do
-    case Protocol.parse(data) do
+    parser = state.continuation || &Protocol.parse/1
+    case parser.(data) do
       {:ok, resp, rest} ->
-        state |> handle_message(resp) |> new_data(rest)
-      {:error, :incomplete} ->
-        %{state | tail: data}
+        state
+        |> handle_message(resp)
+        |> Map.put(:continuation, nil)
+        |> new_data(rest)
+      {:continuation, continuation} ->
+        %{state | continuation: continuation}
     end
   end
 

                  Utils.format_error(reason)]
    :gen_tcp.close(state.socket)
    state = disconnect_and_notify_clients(state, reason)
    {:backoff, @initial_backoff, %{state | tail: "", socket: nil, current_backoff: @initial_backoff}}
  end

  @doc false


  def handle_info({:tcp, socket, data}, %{socket: socket} = state) do
    :ok = :inet.setopts(socket, active: :once)
    state = new_data(state, data)
    {:noreply, state}
  end

