zoovisitor 0.2.5.0 → 0.2.5.1
raw patch · 3 files changed
+26/−13 lines, 3 filesdep +bytestring
Dependencies added: bytestring
Files
- src/ZooKeeper/Internal/Types.hsc +15/−10
- test/Spec.hs +7/−0
- zoovisitor.cabal +4/−3
src/ZooKeeper/Internal/Types.hsc view
@@ -3,17 +3,19 @@ module ZooKeeper.Internal.Types where -import Control.Exception (bracket_)-import Control.Monad (forM)+import Control.Exception (bracket_)+import Control.Monad (forM)+import Data.ByteString.Short (ShortByteString)+import qualified Data.ByteString.Short as BShort (packCStringLen) import Data.Int import Foreign import Foreign.C-import Numeric (showHex)-import Z.Data.CBytes (CBytes)-import qualified Z.Data.CBytes as CBytes-import qualified Z.Data.Text as Text-import Z.Data.Vector (Bytes)-import qualified Z.Foreign as Z+import Numeric (showHex)+import qualified Z.Data.CBytes as CBytes+import Z.Data.CBytes (CBytes)+import qualified Z.Data.Text as Text+import Z.Data.Vector (Bytes)+import qualified Z.Foreign as Z #include "hs_zk.h" @@ -33,14 +35,17 @@ data HsClientID = HsClientID { clientId :: {-# UNPACK #-} !Int64- , clientPasswd :: {-# UNPACK #-} !CBytes+ , clientPasswd :: {-# UNPACK #-} !ShortByteString } deriving (Show, Eq) peekClientId :: ClientID -> IO HsClientID peekClientId (ClientID ptr) = do client_id <- (#peek clientid_t, client_id) ptr+ -- definition in c: char passwd[16];+ let passwd_ptr = (#ptr clientid_t, passwd) ptr+ passwd_len = (#size ((clientid_t *)0)->passwd) -- the pointer is getting from zhandle, so here we don't need to free it- passwd <- CBytes.fromCString =<< (#peek clientid_t, passwd) ptr+ passwd <- BShort.packCStringLen (passwd_ptr, passwd_len) pure $ HsClientID{clientId=client_id, clientPasswd=passwd} newtype ZooLogLevel = ZooLogLevel CInt
test/Spec.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-} module Main where @@ -112,6 +113,12 @@ describe "ZooKeeper.zooState" $ do it "test get state" $ do zooState zh `shouldReturn` ZooConnectedState++ describe "ZooKeeper.zooClientID" $ do+ it "test get data of ClientID" $ do+ zooState zh `shouldReturn` ZooConnectedState+ HsClientID{..} <- peekClientId =<< zooClientID zh+ clientId `shouldNotBe` 0 describe "ZooKeeper.zooRecvTimeout" $ do it "test receive timeout" $ do
zoovisitor.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: zoovisitor-version: 0.2.5.0+version: 0.2.5.1 synopsis: A haskell binding to Apache Zookeeper C library(mt) using Haskell Z project. @@ -44,9 +44,10 @@ ZooKeeper.Recipe.Utils build-depends:- , base >=4.12 && <5+ , base >=4.12 && <5+ , bytestring >=0.10.10.0 , exceptions ^>=0.10- , Z-Data >=0.7.2 && <1.5 || ^>=2.0+ , Z-Data >=0.7.2 && <1.5 || ^>=2.0 includes: hs_zk.h c-sources: cbits/hs_zk.c