Skip to content

Commit

Permalink
ft: improve some decoding paths
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Jul 2, 2024
1 parent 179912e commit 94fcdeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions lib/supavisor/protocol/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,18 @@ defmodule Supavisor.Protocol.Client do
end

def decode_payload(:simple_query, payload) do
case String.split(payload, <<0>>) do
case :binary.split(payload, <<0>>) do
[query, ""] -> query
_ -> :undefined
end
end

def decode_payload(:parse_message, <<0>>), do: :undefined

def decode_payload(:parse_message, payload) do
case String.split(payload, <<0>>) do
[""] ->
:undefined

other ->
case Enum.filter(other, &(&1 != "")) do
[sql] -> sql
message -> message
end
case :binary.split(payload, <<0>>, [:global, :trim_all]) do
[sql] -> sql
message -> message
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/supavisor/protocol/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ defmodule Supavisor.Protocol.Server do

# https://www.postgresql.org/docs/current/protocol-error-fields.html
def decode_payload(:error_response, payload) do
String.split(payload, <<0>>, trim: true)
:binary.split(payload, <<0>>, [:global, :trim_all])
end

def decode_payload(
Expand All @@ -195,7 +195,7 @@ defmodule Supavisor.Protocol.Server do
end

def decode_payload(:password_message, "md5" <> _ = bin) do
case String.split(bin, <<0>>) do
case :binary.split(bin, <<0>>) do
[digest, ""] -> {:md5, digest}
_ -> :undefined
end
Expand Down

0 comments on commit 94fcdeb

Please sign in to comment.