int8.ex (631B)
1 defmodule Postgrex.Extensions.Int8 do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "int8send" 5 6 @int8_range -9_223_372_036_854_775_808..9_223_372_036_854_775_807 7 8 def encode(_) do 9 range = Macro.escape(@int8_range) 10 11 quote location: :keep do 12 int when is_integer(int) and int in unquote(range) -> 13 <<8::int32(), int::int64()>> 14 15 other -> 16 raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, unquote(range)) 17 end 18 end 19 20 def decode(_) do 21 quote location: :keep do 22 <<8::int32(), int::int64()>> -> int 23 end 24 end 25 end