point.ex (803B)
1 defmodule Postgrex.Extensions.Point do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "point_send" 5 6 def encode(_) do 7 quote location: :keep do 8 %Postgrex.Point{x: x, y: y} -> 9 <<16::int32(), x::float64(), y::float64()>> 10 11 other -> 12 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Point) 13 end 14 end 15 16 def decode(_) do 17 quote location: :keep do 18 <<16::int32(), x::float64(), y::float64()>> -> %Postgrex.Point{x: x, y: y} 19 end 20 end 21 22 # used by other extensions 23 def encode_point(%Postgrex.Point{x: x, y: y}, _) do 24 <<x::float64(), y::float64()>> 25 end 26 27 def encode_point(other, wanted) do 28 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, wanted) 29 end 30 end