Permalink
Browse files

Merge pull request #4 from pheaver/bytestring

use ByteString instead of String for values.
  • Loading branch information...
2 parents 97631bb + 48627ce commit db0556fed5c1b2102452599503d78c4e7d4eee7f Sergiy Matusevych committed Jul 26, 2011
Showing with 15 additions and 11 deletions.
  1. +4 −2 src/ZooClient.hs
  2. +9 −7 src/Zookeeper.hsc
  3. +2 −2 zookeeper.cabal
View
@@ -1,6 +1,7 @@
module Main where
+import qualified Data.ByteString.Char8 as B
import System.Environment (getArgs)
import qualified Zookeeper as Zoo
@@ -14,10 +15,11 @@ main = do
putStrLn ("watch: '" ++ path ++ "' :: "
++ show zEventType ++ " " ++ show zState)
+-- TODO we should probably encode the value as UTF-8 in "create" and "set"
run :: Zoo.ZHandle -> String -> [String] -> IO ()
run zh "create" [path, value] = do
- res <- Zoo.create zh path (Just value)
+ res <- Zoo.create zh path (Just $ B.pack value)
Zoo.OpenAclUnsafe Zoo.defaultCreateMode
print res
@@ -30,7 +32,7 @@ run zh "getChildren" [path] = do
print children
run zh "set" (path:value:version) = do
- Zoo.set zh path (Just value) (intVersion version)
+ Zoo.set zh path (Just $ B.pack value) (intVersion version)
run zh "delete" (path:version) = do
Zoo.delete zh path (intVersion version)
View
@@ -15,6 +15,8 @@ import Prelude hiding (init)
import Data.Bits
import Data.Word
+import Data.ByteString (ByteString)
+import qualified Data.ByteString.Char8 as B
import Data.Typeable
import Control.Monad
@@ -120,14 +122,14 @@ close :: ZHandle -> IO ()
recvTimeout :: ZHandle -> IO Int
state :: ZHandle -> IO State
-create :: ZHandle -> String -> Maybe String ->
+create :: ZHandle -> String -> Maybe ByteString ->
Acls -> CreateMode -> IO String
delete :: ZHandle -> String -> Int -> IO ()
exists :: ZHandle -> String -> Watch -> IO (Maybe Stat)
-get :: ZHandle -> String -> Watch -> IO (Maybe String, Stat)
+get :: ZHandle -> String -> Watch -> IO (Maybe ByteString, Stat)
getChildren :: ZHandle -> String -> Watch -> IO [String]
-set :: ZHandle -> String -> Maybe String -> Int -> IO ()
+set :: ZHandle -> String -> Maybe ByteString -> Int -> IO ()
getAcl :: ZHandle -> String -> IO (Acls, Stat)
setAcl :: ZHandle -> String -> Int -> Acls -> IO ()
@@ -344,11 +346,11 @@ copyStringVec bufPtr = do
mapM (peekCString <=< peek . plusPtr vec . (* #size char*)) [0..len-1]
withMaybeCStringLen Nothing func = func (nullPtr, -1)
-withMaybeCStringLen (Just str) func = withCStringLen str func
+withMaybeCStringLen (Just str) func = B.useAsCStringLen str func
-peekMaybeCStringLen buf len
+packMaybeCStringLen buf len
| len == maxBound || len < 0 = return Nothing
- | otherwise = liftM Just $ peekCStringLen (buf, len)
+ | otherwise = liftM Just $ B.packCStringLen (buf, len)
watchFlag Watch = 1
watchFlag NoWatch = 0
@@ -428,7 +430,7 @@ get zh path watch =
checkError ("get: " ++ path) $
zoo_get zhPtr pathPtr (watchFlag watch) buf bufLen statPtr
stat <- copyStat statPtr
- maybeBuf <- peek bufLen >>= peekMaybeCStringLen buf
+ maybeBuf <- peek bufLen >>= packMaybeCStringLen buf
return (maybeBuf, stat))))))
getChildren zh path watch =
View
@@ -11,15 +11,15 @@ Cabal-Version: >=1.8
Library
Ghc-Options: -threaded -O2
Extra-Libraries: zookeeper_mt
- Build-Depends: base >= 4 && < 5
+ Build-Depends: base >= 4 && < 5, bytestring == 0.9.*
Hs-source-dirs: src
Exposed-modules: Zookeeper
Extensions: DeriveDataTypeable
Executable ZooClient
Ghc-Options: -threaded -O2
Extra-Libraries: zookeeper_mt
- Build-Depends: base >= 4 && < 5
+ Build-Depends: base >= 4 && < 5, bytestring == 0.9.*
Hs-source-dirs: src
Main-is: ZooClient.hs
Other-modules: Zookeeper

0 comments on commit db0556f

Please sign in to comment.