zf

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

oid.ex (1039B)


      1 defmodule Postgrex.Extensions.OID do
      2   @moduledoc false
      3   @oid_senders ~w(oidsend regprocsend regproceduresend regopersend
      4                   regoperatorsend regclasssend regtypesend xidsend cidsend)
      5 
      6   import Postgrex.BinaryUtils, warn: false
      7   use Postgrex.BinaryExtension, Enum.map(@oid_senders, &{:send, &1})
      8 
      9   @oid_range 0..4_294_967_295
     10 
     11   def encode(_) do
     12     range = Macro.escape(@oid_range)
     13 
     14     quote location: :keep do
     15       oid when is_integer(oid) and oid in unquote(range) ->
     16         <<4::int32(), oid::uint32()>>
     17 
     18       binary when is_binary(binary) ->
     19         msg =
     20           "you tried to use a binary for an oid type " <>
     21             "(#{binary}) when an integer was expected. See " <>
     22             "https://github.com/elixir-ecto/postgrex#oid-type-encoding"
     23 
     24         raise ArgumentError, msg
     25 
     26       other ->
     27         raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, unquote(range))
     28     end
     29   end
     30 
     31   def decode(_) do
     32     quote location: :keep do
     33       <<4::int32(), oid::uint32()>> -> oid
     34     end
     35   end
     36 end