packages feed

postgresql-binary 0.9.2 → 0.9.3

raw patch · 6 files changed

+138/−1 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ PostgreSQL.Binary.Data: InetIPv4 :: IPv4 -> Inet
+ PostgreSQL.Binary.Data: InetIPv4Subnet :: IPv4 -> Netmask -> Inet
+ PostgreSQL.Binary.Data: InetIPv6 :: IPv6 -> Inet
+ PostgreSQL.Binary.Data: InetIPv6Subnet :: IPv6 -> Netmask -> Inet
+ PostgreSQL.Binary.Data: afInet :: Word8
+ PostgreSQL.Binary.Data: afInet6 :: Word8
+ PostgreSQL.Binary.Data: data Inet
+ PostgreSQL.Binary.Data: instance GHC.Classes.Eq PostgreSQL.Binary.Data.Inet
+ PostgreSQL.Binary.Data: instance GHC.Show.Show PostgreSQL.Binary.Data.Inet
+ PostgreSQL.Binary.Data: ipv4Size :: Int8
+ PostgreSQL.Binary.Data: ipv6Size :: Int8
+ PostgreSQL.Binary.Data: isCidr :: Word8
+ PostgreSQL.Binary.Data: maxNetmaskIPv4 :: Word8
+ PostgreSQL.Binary.Data: maxNetmaskIPv6 :: Word8
+ PostgreSQL.Binary.Data: type IPv4 = (Word8, Word8, Word8, Word8)
+ PostgreSQL.Binary.Data: type IPv6 = (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
+ PostgreSQL.Binary.Data: type Netmask = Word8
+ PostgreSQL.Binary.Decoder: inet :: Decoder Inet
+ PostgreSQL.Binary.Encoder: inet :: Encoder Inet

Files

library/PostgreSQL/Binary/Data.hs view
@@ -56,3 +56,45 @@ --  type Numeric =   (Int16, Word16, Vector Int16)++-- |+-- Representation of the PostgreSQL Network Address Type @inet@.+--+-- The Inet type holds an IPv4 or IPv6 host address, and optionally its subnet.+-- The subnet is represented by the number of network address bits present in the host address (the "netmask").+-- If the subnet portion is missing, the netmask is 32 for IPv4 and 128 for IPv6.+data Inet+  = InetIPv4 IPv4+  | InetIPv4Subnet IPv4 Netmask+  | InetIPv6 IPv6+  | InetIPv6Subnet IPv6 Netmask+  deriving (Eq, Show)++type IPv4 = (Word8, Word8, Word8, Word8)++type IPv6 = (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)++type Netmask = Word8++maxNetmaskIPv4 :: Word8+maxNetmaskIPv4 = 32++maxNetmaskIPv6 :: Word8+maxNetmaskIPv6 = 128++-- | Address family AF_INET+afInet :: Word8+afInet = 2++-- | Address family AF_INET6+afInet6 :: Word8+afInet6 = 3++ipv4Size :: Int8+ipv4Size = 4++ipv6Size :: Int8+ipv6Size = 16++isCidr :: Word8+isCidr = 0
library/PostgreSQL/Binary/Decoder.hs view
@@ -17,6 +17,7 @@   fn,   numeric,   uuid,+  inet,   json_ast,   json_bytes,   jsonb_ast,@@ -151,6 +152,47 @@ uuid :: Decoder UUID uuid =   UUID.fromWords <$> intOfSize 4 <*> intOfSize 4 <*> intOfSize 4 <*> intOfSize 4++{-# INLINABLE ipv4 #-}+ipv4 :: Decoder Data.IPv4+ipv4 =+  (,,,) <$> intOfSize 1 <*> intOfSize 1 <*> intOfSize 1 <*> intOfSize 1++{-# INLINABLE ipv6 #-}+ipv6 :: Decoder Data.IPv6+ipv6 =+  (,,,,,,,) <$> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2 <*> intOfSize 2++{-# INLINABLE inet #-}+inet :: Decoder Data.Inet+inet = do+  af <- intOfSize 1+  netmask <- intOfSize 1+  isCidr <- intOfSize 1+  ipSize <- intOfSize 1+  if af == Data.afInet+    then do+      ip <- ipv4+      return $ inetIPv4FromBytes af netmask isCidr ipSize ip+    else do+      ip <- ipv6+      return $ inetIPv6FromBytes af netmask isCidr ipSize ip++{-# INLINABLE inetIPv4FromBytes #-}+inetIPv4FromBytes:: Word8 -> Word8 -> Word8 -> Int8 -> Data.IPv4 -> Data.Inet+inetIPv4FromBytes _ netmask _ _ ip =+  if netmask == Data.maxNetmaskIPv4 then+    Data.InetIPv4 ip+  else+    Data.InetIPv4Subnet ip netmask++{-# INLINABLE inetIPv6FromBytes #-}+inetIPv6FromBytes:: Word8 -> Word8 -> Word8 -> Int8 -> Data.IPv6 -> Data.Inet+inetIPv6FromBytes _ netmask _ _ ip =+  if netmask == Data.maxNetmaskIPv6 then+    Data.InetIPv6 ip+  else+    Data.InetIPv6Subnet ip netmask  {-# INLINABLE json_ast #-} json_ast :: Decoder Aeson.Value
library/PostgreSQL/Binary/Encoder.hs view
@@ -16,6 +16,7 @@   bool,   numeric,   uuid,+  inet,   json_ast,   json_bytes,   jsonb_ast,@@ -95,11 +96,29 @@ tuple4 e1 e2 e3 e4 =   \(v1, v2, v3, v4) -> e1 v1 <> e2 v2 <> e3 v3 <> e4 v4 +{-# INLINE tuple5 #-}+tuple5 :: Encoder a -> Encoder b -> Encoder c -> Encoder d -> Encoder e -> Encoder (a, b, c, d, e)+tuple5 e1 e2 e3 e4 e5 (v1, v2, v3, v4, v5) = e1 v1 <> e2 v2 <> e3 v3 <> e4 v4 <> e5 v5++{-# INLINE tuple8 #-}+tuple8 :: Encoder a -> Encoder b -> Encoder c -> Encoder d -> Encoder e -> Encoder f -> Encoder g -> Encoder h -> Encoder (a, b, c, d, e, f, g, h)+tuple8 e1 e2 e3 e4 e5 e6 e7 e8 (v1, v2, v3, v4, v5, v6, v7, v8) = e1 v1 <> e2 v2 <> e3 v3 <> e4 v4 <> e5 v5 <> e6 v6 <> e7 v7 <> e8 v8+ {-# INLINE premap #-} premap :: (a -> b) -> Encoder b -> Encoder a premap f e =   e . f +{-# INLINE int_int8 #-}+int_int8 :: Encoder Int8+int_int8 =+  Builder.int8++{-# INLINE int_word8 #-}+int_word8 :: Encoder Word8+int_word8 =+  Builder.word8+ {-# INLINE int2_int16 #-} int2_int16 :: Encoder Int16 int2_int16 =@@ -221,6 +240,28 @@ uuid :: Encoder UUID uuid =   premap UUID.toWords (tuple4 int4_word32 int4_word32 int4_word32 int4_word32)++{-# INLINABLE inetIPv4 #-}+inetIPv4 :: Encoder (Word8, Word8, Word8, Int8, Data.IPv4)+inetIPv4 =+  tuple5 int_word8 int_word8 int_word8 int_int8 $ tuple4 int_word8 int_word8 int_word8 int_word8++{-# INLINABLE inetIPv6 #-}+inetIPv6 :: Encoder (Word8, Word8, Word8, Int8, Data.IPv6)+inetIPv6 =+  tuple5 int_word8 int_word8 int_word8 int_int8 $+  tuple8 int2_word16 int2_word16 int2_word16 int2_word16 int2_word16 int2_word16 int2_word16 int2_word16++{-# INLINABLE inet #-}+inet :: Encoder Data.Inet+inet i@(Data.InetIPv4 ipv4) =+  premap (const (Data.afInet, Data.maxNetmaskIPv4, Data.isCidr, Data.ipv4Size, ipv4)) inetIPv4 i+inet i@(Data.InetIPv4Subnet ipv4 netmask) =+  premap (const (Data.afInet, netmask, Data.isCidr, Data.ipv4Size, ipv4)) inetIPv4 i+inet i@(Data.InetIPv6 ipv6) =+  premap (const (Data.afInet6, Data.maxNetmaskIPv6, Data.isCidr, Data.ipv6Size, ipv6)) inetIPv6 i+inet i@(Data.InetIPv6Subnet ipv6 netmask) =+  premap (const (Data.afInet6, netmask, Data.isCidr, Data.ipv6Size, ipv6)) inetIPv6 i  {-# INLINABLE json_ast #-} json_ast :: Encoder Aeson.Value
postgresql-binary.cabal view
@@ -1,7 +1,7 @@ name:   postgresql-binary version:-  0.9.2+  0.9.3 synopsis:   Encoders and decoders for the PostgreSQL's binary format description:
tasty/Main.hs view
@@ -141,6 +141,8 @@             ,             stdRoundtrip "uuid" Gens.uuid PTI.uuid Encoder.uuid Decoder.uuid             ,+            stdRoundtrip "inet" Gens.inet PTI.inet Encoder.inet Decoder.inet+            ,             stdRoundtrip "int2_int16" Gens.auto PTI.int2 Encoder.int2_int16 Decoder.int             ,             stdRoundtrip "int2_word16" Gens.auto PTI.int2 Encoder.int2_word16 Decoder.int
tasty/Main/Gens.hs view
@@ -120,6 +120,16 @@ uuid =   UUID.fromWords <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary +inet :: Gen Data.Inet+inet = do+  ipv6 <- choose (True, False)+  subnetOn <- choose (True, False)+  case (ipv6, subnetOn) of+    (False, False) -> Data.InetIPv4 <$> ((,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary)+    (False, True) ->  Data.InetIPv4Subnet <$> ((,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary) <*> choose (0, Data.maxNetmaskIPv4 - 1)+    (True, False) -> Data.InetIPv6 <$> ((,,,,,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary)+    (True, True) -> Data.InetIPv6Subnet <$> ((,,,,,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary) <*> choose (0, Data.maxNetmaskIPv6 - 1)+ arrayRep :: Gen (Word32, Data.Array) arrayRep =   do