int2.ex (591B)
1 defmodule Postgrex.Extensions.Int2 do 2 @moduledoc false 3 import Postgrex.BinaryUtils, warn: false 4 use Postgrex.BinaryExtension, send: "int2send" 5 6 @int2_range -32768..32767 7 8 def encode(_) do 9 range = Macro.escape(@int2_range) 10 11 quote location: :keep do 12 int when is_integer(int) and int in unquote(range) -> 13 <<2::int32(), int::int16()>> 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 <<2::int32(), int::int16()>> -> int 23 end 24 end 25 end