line.ex (720B)
1 defmodule Postgrex.Extensions.Line do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "line_send" 5 6 def encode(_) do 7 quote location: :keep do 8 %Postgrex.Line{a: a, b: b, c: c} when is_number(a) and is_number(b) and is_number(c) -> 9 # a, b, c are 8 bytes each 10 <<24::int32(), a::float64(), b::float64(), c::float64()>> 11 12 other -> 13 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Line) 14 end 15 end 16 17 def decode(_) do 18 quote location: :keep do 19 # a, b, c are 8 bytes each 20 <<24::int32(), a::float64(), b::float64(), c::float64()>> -> 21 %Postgrex.Line{a: a, b: b, c: c} 22 end 23 end 24 end