text-postgresql 0.0.1.0 → 0.0.2.0
raw patch · 5 files changed
+36/−40 lines, 5 files
Files
- src/Data/PostgreSQL/NetworkAddress.hs +13/−22
- src/Database/PostgreSQL/Parser.hs +7/−7
- src/Database/PostgreSQL/Printer.hs +6/−6
- test/ppIso.hs +9/−4
- text-postgresql.cabal +1/−1
src/Data/PostgreSQL/NetworkAddress.hs view
@@ -11,7 +11,7 @@ -- http://www.postgresql.org/docs/current/static/datatype-net-types.html module Data.PostgreSQL.NetworkAddress ( NetAddress (..)- , HostAddress, hostAddress, hostAddressOctets+ , V4HostAddress (..), v4HostAddressOctets , V6HostAddress (..), v6HostAddressLong, v6HostAddressWords , v6HostAddress, v6HostAddressL, v6HostAddressR @@ -20,31 +20,22 @@ import Control.Applicative (pure) import Control.Monad (guard)-import Data.Word (Word8, Word16, Word32)-import Data.Bits ((.&.), (.|.), shiftL, shiftR)+import Data.Word (Word8, Word16) --- | Same as HostAddress of network package. Definition to reduce dependency.-type HostAddress = Word32--hostAddress :: Word8 -> Word8 -> Word8 -> Word8 -> HostAddress-hostAddress a b c d =- fromIntegral a .|.- fromIntegral b `shiftL` 8 .|.- fromIntegral c `shiftL` 16 .|.- fromIntegral d `shiftL` 24+-- | Host address type along with IPv4 address string.+data V4HostAddress =+ V4HostAddress !Word8 !Word8 !Word8 !Word8+ deriving (Eq, Ord, Show) -hostAddressOctets :: HostAddress -> (Word8, Word8, Word8, Word8)-hostAddressOctets ha =- ( getWord8 0,- getWord8 8,- getWord8 16,- getWord8 24 )- where- getWord8 n = fromIntegral $ (ha `shiftR` n) .&. 0xFF+v4HostAddressOctets :: V4HostAddress -> (Word8, Word8, Word8, Word8)+v4HostAddressOctets (V4HostAddress a b c d) = (a, b, c, d) --- | Not same as HostAddress6 of network package, because HostAddress6 has host-byteorder.+-- | Host address type along with IPv6 address string.+-- Each 'Word16' value is host byte order.+-- Host byte order is portable in programs on its own host.+-- Network byte order is only needed, when communicating other hosts. data V6HostAddress = V6HostAddress !Word16 !Word16 !Word16 !Word16 !Word16 !Word16 !Word16 !Word16 deriving (Eq, Ord, Show)@@ -73,7 +64,7 @@ data NetAddress- = NetAddress4 !HostAddress !Word8+ = NetAddress4 !V4HostAddress !Word8 | NetAddress6 !V6HostAddress !Word8 deriving (Eq, Ord, Show)
src/Database/PostgreSQL/Parser.hs view
@@ -4,7 +4,7 @@ , eof , netAddress- , hostAddress, decMask4+ , v4HostAddress, decMask4 , v6HostAddress, decMask6 ) where @@ -17,7 +17,7 @@ import Text.Parser.List (runParser, evalParser, eof, noteP, satisfy', satisfy) import qualified Text.Parser.List as P-import Data.PostgreSQL.NetworkAddress (NetAddress (..), HostAddress, V6HostAddress)+import Data.PostgreSQL.NetworkAddress (NetAddress (..), V4HostAddress, V6HostAddress) import qualified Data.PostgreSQL.NetworkAddress as D @@ -69,12 +69,12 @@ slash :: Parser Char slash = char '/' -hostAddress :: Parser HostAddress-hostAddress = D.hostAddress <$> decW8 <* dot <*> decW8 <* dot <*> decW8 <* dot <*> decW8+v4HostAddress :: Parser V4HostAddress+v4HostAddress = D.V4HostAddress <$> decW8 <* dot <*> decW8 <* dot <*> decW8 <* dot <*> decW8 -_exampleHostAddress :: [Either String HostAddress]+_exampleHostAddress :: [Either String V4HostAddress] _exampleHostAddress =- [ evalParser (hostAddress <* eof) s+ [ evalParser (v4HostAddress <* eof) s | s <- [ "0.0.0.0", "192.168.0.1" ] ] @@ -121,7 +121,7 @@ netAddress :: Parser NetAddress netAddress =- NetAddress4 <$> hostAddress <*> optional' mask4bits (slash *> decMask4) <|>+ NetAddress4 <$> v4HostAddress <*> optional' mask4bits (slash *> decMask4) <|> NetAddress6 <$> v6HostAddress <*> optional' mask6bits (slash *> decMask6) _exampleNetAddress :: [Either String NetAddress]
src/Database/PostgreSQL/Printer.hs view
@@ -1,7 +1,7 @@ module Database.PostgreSQL.Printer ( Printer, execPrinter- , hostAddress+ , v4HostAddress , v6HostAddress , netAddress ) where@@ -11,7 +11,7 @@ import Text.Printer.List (token, list, execPrinter) import qualified Text.Printer.List as P import Data.PostgreSQL.NetworkAddress- (HostAddress, hostAddressOctets, V6HostAddress, v6HostAddressWords, NetAddress (..))+ (V4HostAddress, v4HostAddressOctets, V6HostAddress, v6HostAddressWords, NetAddress (..)) type Printer a = P.Printer Char a@@ -36,9 +36,9 @@ slash :: PrintM () slash = token '/' -hostAddress :: Printer HostAddress-hostAddress ha = do- let (a, b, c, d) = hostAddressOctets ha+v4HostAddress :: Printer V4HostAddress+v4HostAddress ha = do+ let (a, b, c, d) = v4HostAddressOctets ha dec a dot dec b@@ -69,7 +69,7 @@ netAddress :: Printer NetAddress netAddress = d where d (NetAddress4 ha m) = do- hostAddress ha+ v4HostAddress ha slash dec m d (NetAddress6 v6 m) = do
test/ppIso.hs view
@@ -15,6 +15,11 @@ import qualified Database.PostgreSQL.Printer as Printer +instance Arbitrary V4HostAddress where+ arbitrary =+ V4HostAddress+ <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary+ instance Arbitrary V6HostAddress where arbitrary = V6HostAddress@@ -37,9 +42,9 @@ isoProp pr ps a = Right a == (evalParser ps $ execPrinter pr a) -prop_hostAddressIso :: HostAddress -> Bool-prop_hostAddressIso =- isoProp Printer.hostAddress Parser.hostAddress+prop_v4HostAddressIso :: V4HostAddress -> Bool+prop_v4HostAddressIso =+ isoProp Printer.v4HostAddress Parser.v4HostAddress prop_v6HostAddressIso :: V6HostAddress -> Bool prop_v6HostAddressIso =@@ -51,7 +56,7 @@ tests :: [Test] tests =- [ qcTest "v4 address iso - print parse" prop_hostAddressIso+ [ qcTest "v4 address iso - print parse" prop_v4HostAddressIso , qcTest "v6 address iso - print parse" prop_v6HostAddressIso , qcTest "network address iso - print parse" prop_netAddressIso ]
text-postgresql.cabal view
@@ -1,5 +1,5 @@ name: text-postgresql-version: 0.0.1.0+version: 0.0.2.0 synopsis: Parser and Printer of PostgreSQL extended types description: This package involves parser and printer for text expressions of PostgreSQL extended types.