{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} ------------------------------------------------------------------- -- | -- Module : Network.MessagePackRpc.Client -- Copyright : (c) Hideyuki Tanaka, 2010-2015 -- License : BSD3 -- -- Maintainer: Hideyuki Tanaka -- Stability : experimental -- Portability: portable -- -- This module is client library of MessagePack-RPC. -- The specification of MessagePack-RPC is at -- . -- -- A simple example: -- -- > import Network.MessagePackRpc.Client -- > -- > add :: Int -> Int -> Client Int -- > add = call "add" -- > -- > main = execClient "localhost" 5000 $ do -- > ret <- add 123 456 -- > liftIO $ print ret -- -------------------------------------------------------------------- module Network.MessagePack.Client.Basic ( -- * MessagePack Client type Client , ClientT , execClient -- * Call RPC method , call -- * RPC error , RpcError (..) , RpcType (..) ) where import qualified Control.Monad.State.Strict as CMS import qualified Data.ByteString as S import Data.Conduit (($$+)) import Data.Conduit.Network (appSink, appSource, clientSettings, runTCPClient) import Network.MessagePack.Client.Internal import Network.MessagePack.Types.Client import Network.MessagePack.Types.Error execClient :: S.ByteString -> Int -> Client a -> IO a execClient host port client = runTCPClient (clientSettings port host) $ \ad -> do (rsrc, _) <- appSource ad $$+ return () CMS.evalStateT (runClientT client) Connection { connSource = rsrc , connSink = appSink ad , connMsgId = 0 , connMths = [] }