zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

int4.ex (607B)


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