circle.ex (737B)
1 defmodule Postgrex.Extensions.Circle do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "circle_send" 5 6 def encode(_) do 7 quote location: :keep do 8 %Postgrex.Circle{center: %Postgrex.Point{x: x, y: y}, radius: r} 9 when is_number(x) and is_number(y) and is_number(r) and r >= 0 -> 10 <<24::int32(), x::float64(), y::float64(), r::float64()>> 11 12 other -> 13 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Path) 14 end 15 end 16 17 def decode(_) do 18 quote location: :keep do 19 <<24::int32(), x::float64(), y::float64(), r::float64()>> -> 20 %Postgrex.Circle{center: %Postgrex.Point{x: x, y: y}, radius: r} 21 end 22 end 23 end