thrift-lib-0.1.0.1: test/gen-hs2/Math/Calculator/Client.hs
-----------------------------------------------------------------
-- Autogenerated by Thrift
--
-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-- @generated
-----------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -fno-warn-unused-imports#-}
{-# OPTIONS_GHC -fno-warn-overlapping-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-record-updates#-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Math.Calculator.Client
(Calculator, divide, divideIO, send_divide, _build_divide,
recv_divide, _parse_divide, quotRem, quotRemIO, send_quotRem,
_build_quotRem, recv_quotRem, _parse_quotRem, put, putIO, send_put,
_build_put, putMany, putManyIO, send_putMany, _build_putMany, get,
getIO, send_get, _build_get, recv_get, _parse_get, unimplemented,
unimplementedIO, send_unimplemented, _build_unimplemented,
recv_unimplemented, _parse_unimplemented)
where
import qualified Control.Arrow as Arrow
import qualified Control.Concurrent as Concurrent
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
import qualified Control.Monad.Trans.Class as Trans
import qualified Control.Monad.Trans.Reader as Reader
import qualified Data.ByteString.Builder as ByteString
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Int as Int
import qualified Data.List as List
import qualified Data.Proxy as Proxy
import qualified Math.Adder.Client as Adder
import qualified Prelude as Prelude
import qualified Thrift.Binary.Parser as Parser
import qualified Thrift.Codegen as Thrift
import qualified Thrift.Protocol.ApplicationException.Types
as Thrift
import Data.Monoid ((<>))
import Prelude ((==), (=<<), (>>=), (<$>), (.))
import Math.Types
data Calculator
type instance Thrift.Super Calculator = Adder.Adder
divide ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Prelude.Double ->
Prelude.Double -> Thrift.ThriftM p c s Prelude.Double
divide __field__dividend __field__divisor
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift
(divideIO _proxy _channel _counter _opts __field__dividend
__field__divisor)
divideIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.RpcOptions ->
Prelude.Double -> Prelude.Double -> Prelude.IO Prelude.Double
divideIO _proxy _channel _counter _opts __field__dividend
__field__divisor
= do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
(recv_divide _proxy)
send_divide _proxy _channel _counter _sendCob _recvCob _opts
__field__dividend
__field__divisor
Thrift.wait _handle
send_divide ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RecvCallback ->
Thrift.RpcOptions ->
Prelude.Double -> Prelude.Double -> Prelude.IO ()
send_divide _proxy _channel _counter _sendCob _recvCob _rpcOpts
__field__dividend __field__divisor
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString
(_build_divide _proxy _seqNum __field__dividend __field__divisor))
Thrift.sendRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_recvCob
recv_divide ::
(Thrift.Protocol p) =>
Proxy.Proxy p ->
Thrift.Response ->
Prelude.Either Exception.SomeException Prelude.Double
recv_divide _proxy (Thrift.Response _response _)
= Monad.join
(Arrow.left (Exception.SomeException . Thrift.ProtocolException)
(Parser.parse (_parse_divide _proxy) _response))
_build_divide ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Int.Int32 -> Prelude.Double -> Prelude.Double -> ByteString.Builder
_build_divide _proxy _seqNum __field__dividend __field__divisor
= Thrift.genMsgBegin _proxy "divide" 1 _seqNum <>
Thrift.genStruct _proxy
(Thrift.genField _proxy "dividend" (Thrift.getDoubleType _proxy) 1
0
(Thrift.genDouble _proxy __field__dividend)
:
Thrift.genField _proxy "divisor" (Thrift.getDoubleType _proxy) 2 1
(Thrift.genDouble _proxy __field__divisor)
: [])
<> Thrift.genMsgEnd _proxy
_parse_divide ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Parser.Parser
(Prelude.Either Exception.SomeException Prelude.Double)
_parse_divide _proxy
= do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
_result <- case _msgTy of
1 -> Prelude.fail "divide: expected reply but got function call"
2 | _name == "divide" ->
do let
_idMap
= HashMap.fromList [("divide_success", 0), ("divisionError", 1)]
_fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
case _fieldBegin of
Thrift.FieldBegin _type _id _bool -> do case _id of
0 | _type ==
Thrift.getDoubleType
_proxy
->
Prelude.fmap
Prelude.Right
(Thrift.parseDouble
_proxy)
1 | _type ==
Thrift.getStructType
_proxy
->
Prelude.fmap
(Prelude.Left .
Exception.SomeException)
(Thrift.parseStruct
_proxy
::
Parser.Parser
DivideByZero)
_ -> Prelude.fail
(Prelude.unwords
["unrecognized exception, type:",
Prelude.show
_type,
"field id:",
Prelude.show _id])
Thrift.FieldEnd -> Prelude.fail "no response"
| Prelude.otherwise -> Prelude.fail "reply function does not match"
3 -> Prelude.fmap (Prelude.Left . Exception.SomeException)
(Thrift.parseStruct _proxy ::
Parser.Parser Thrift.ApplicationException)
4 -> Prelude.fail
"divide: expected reply but got oneway function call"
_ -> Prelude.fail "divide: invalid message type"
Thrift.parseMsgEnd _proxy
Prelude.return _result
quotRem ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Prelude.Int -> Prelude.Int -> Thrift.ThriftM p c s QuotRemResponse
quotRem __field__dividend __field__divisor
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift
(quotRemIO _proxy _channel _counter _opts __field__dividend
__field__divisor)
quotRemIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.RpcOptions ->
Prelude.Int -> Prelude.Int -> Prelude.IO QuotRemResponse
quotRemIO _proxy _channel _counter _opts __field__dividend
__field__divisor
= do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
(recv_quotRem _proxy)
send_quotRem _proxy _channel _counter _sendCob _recvCob _opts
__field__dividend
__field__divisor
Thrift.wait _handle
send_quotRem ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RecvCallback ->
Thrift.RpcOptions -> Prelude.Int -> Prelude.Int -> Prelude.IO ()
send_quotRem _proxy _channel _counter _sendCob _recvCob _rpcOpts
__field__dividend __field__divisor
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString
(_build_quotRem _proxy _seqNum __field__dividend __field__divisor))
Thrift.sendRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_recvCob
recv_quotRem ::
(Thrift.Protocol p) =>
Proxy.Proxy p ->
Thrift.Response ->
Prelude.Either Exception.SomeException QuotRemResponse
recv_quotRem _proxy (Thrift.Response _response _)
= Monad.join
(Arrow.left (Exception.SomeException . Thrift.ProtocolException)
(Parser.parse (_parse_quotRem _proxy) _response))
_build_quotRem ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Int.Int32 -> Prelude.Int -> Prelude.Int -> ByteString.Builder
_build_quotRem _proxy _seqNum __field__dividend __field__divisor
= Thrift.genMsgBegin _proxy "quotRem" 1 _seqNum <>
Thrift.genStruct _proxy
(Thrift.genField _proxy "dividend" (Thrift.getI64Type _proxy) 1 0
((Thrift.genI64 _proxy . Prelude.fromIntegral) __field__dividend)
:
Thrift.genField _proxy "divisor" (Thrift.getI64Type _proxy) 2 1
((Thrift.genI64 _proxy . Prelude.fromIntegral) __field__divisor)
: [])
<> Thrift.genMsgEnd _proxy
_parse_quotRem ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Parser.Parser
(Prelude.Either Exception.SomeException QuotRemResponse)
_parse_quotRem _proxy
= do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
_result <- case _msgTy of
1 -> Prelude.fail "quotRem: expected reply but got function call"
2 | _name == "quotRem" ->
do let
_idMap = HashMap.fromList [("quotRem_success", 0)]
_fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
case _fieldBegin of
Thrift.FieldBegin _type _id _bool -> do case _id of
0 | _type ==
Thrift.getStructType
_proxy
->
Prelude.fmap
Prelude.Right
(Thrift.parseStruct
_proxy)
_ -> Prelude.fail
(Prelude.unwords
["unrecognized exception, type:",
Prelude.show
_type,
"field id:",
Prelude.show _id])
Thrift.FieldEnd -> Prelude.fail "no response"
| Prelude.otherwise -> Prelude.fail "reply function does not match"
3 -> Prelude.fmap (Prelude.Left . Exception.SomeException)
(Thrift.parseStruct _proxy ::
Parser.Parser Thrift.ApplicationException)
4 -> Prelude.fail
"quotRem: expected reply but got oneway function call"
_ -> Prelude.fail "quotRem: invalid message type"
Thrift.parseMsgEnd _proxy
Prelude.return _result
put ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Prelude.Int -> Thrift.ThriftM p c s ()
put __field__val
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift (putIO _proxy _channel _counter _opts __field__val)
putIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter -> Thrift.RpcOptions -> Prelude.Int -> Prelude.IO ()
putIO _proxy _channel _counter _opts __field__val
= do _handle <- Concurrent.newEmptyMVar
send_put _proxy _channel _counter (Concurrent.putMVar _handle)
_opts
__field__val
Concurrent.takeMVar _handle >>=
Prelude.maybe (Prelude.return ()) Exception.throw
send_put ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RpcOptions -> Prelude.Int -> Prelude.IO ()
send_put _proxy _channel _counter _sendCob _rpcOpts __field__val
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString
(_build_put _proxy _seqNum __field__val))
Thrift.sendOnewayRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_build_put ::
Thrift.Protocol p =>
Proxy.Proxy p -> Int.Int32 -> Prelude.Int -> ByteString.Builder
_build_put _proxy _seqNum __field__val
= Thrift.genMsgBegin _proxy "put" 1 _seqNum <>
Thrift.genStruct _proxy
(Thrift.genField _proxy "val" (Thrift.getI64Type _proxy) 1 0
((Thrift.genI64 _proxy . Prelude.fromIntegral) __field__val)
: [])
<> Thrift.genMsgEnd _proxy
putMany ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
[Prelude.Int] -> Thrift.ThriftM p c s ()
putMany __field__val
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift (putManyIO _proxy _channel _counter _opts __field__val)
putManyIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.RpcOptions -> [Prelude.Int] -> Prelude.IO ()
putManyIO _proxy _channel _counter _opts __field__val
= do _handle <- Concurrent.newEmptyMVar
send_putMany _proxy _channel _counter (Concurrent.putMVar _handle)
_opts
__field__val
Concurrent.takeMVar _handle >>=
Prelude.maybe (Prelude.return ()) Exception.throw
send_putMany ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RpcOptions -> [Prelude.Int] -> Prelude.IO ()
send_putMany _proxy _channel _counter _sendCob _rpcOpts
__field__val
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString
(_build_putMany _proxy _seqNum __field__val))
Thrift.sendOnewayRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_build_putMany ::
Thrift.Protocol p =>
Proxy.Proxy p -> Int.Int32 -> [Prelude.Int] -> ByteString.Builder
_build_putMany _proxy _seqNum __field__val
= Thrift.genMsgBegin _proxy "putMany" 1 _seqNum <>
Thrift.genStruct _proxy
(Thrift.genField _proxy "val" (Thrift.getListType _proxy) 1 0
(Thrift.genList _proxy (Thrift.getI64Type _proxy)
(Thrift.genI64 _proxy . Prelude.fromIntegral)
__field__val)
: [])
<> Thrift.genMsgEnd _proxy
get ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Thrift.ThriftM p c s Prelude.Int
get
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift (getIO _proxy _channel _counter _opts)
getIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter -> Thrift.RpcOptions -> Prelude.IO Prelude.Int
getIO _proxy _channel _counter _opts
= do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
(recv_get _proxy)
send_get _proxy _channel _counter _sendCob _recvCob _opts
Thrift.wait _handle
send_get ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RecvCallback -> Thrift.RpcOptions -> Prelude.IO ()
send_get _proxy _channel _counter _sendCob _recvCob _rpcOpts
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString (_build_get _proxy _seqNum))
Thrift.sendRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_recvCob
recv_get ::
(Thrift.Protocol p) =>
Proxy.Proxy p ->
Thrift.Response ->
Prelude.Either Exception.SomeException Prelude.Int
recv_get _proxy (Thrift.Response _response _)
= Monad.join
(Arrow.left (Exception.SomeException . Thrift.ProtocolException)
(Parser.parse (_parse_get _proxy) _response))
_build_get ::
Thrift.Protocol p =>
Proxy.Proxy p -> Int.Int32 -> ByteString.Builder
_build_get _proxy _seqNum
= Thrift.genMsgBegin _proxy "get" 1 _seqNum <>
Thrift.genStruct _proxy []
<> Thrift.genMsgEnd _proxy
_parse_get ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Parser.Parser (Prelude.Either Exception.SomeException Prelude.Int)
_parse_get _proxy
= do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
_result <- case _msgTy of
1 -> Prelude.fail "get: expected reply but got function call"
2 | _name == "get" ->
do let
_idMap = HashMap.fromList [("get_success", 0)]
_fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
case _fieldBegin of
Thrift.FieldBegin _type _id _bool -> do case _id of
0 | _type ==
Thrift.getI64Type
_proxy
->
Prelude.fmap
Prelude.Right
(Prelude.fromIntegral
<$>
Thrift.parseI64
_proxy)
_ -> Prelude.fail
(Prelude.unwords
["unrecognized exception, type:",
Prelude.show
_type,
"field id:",
Prelude.show _id])
Thrift.FieldEnd -> Prelude.fail "no response"
| Prelude.otherwise -> Prelude.fail "reply function does not match"
3 -> Prelude.fmap (Prelude.Left . Exception.SomeException)
(Thrift.parseStruct _proxy ::
Parser.Parser Thrift.ApplicationException)
4 -> Prelude.fail
"get: expected reply but got oneway function call"
_ -> Prelude.fail "get: invalid message type"
Thrift.parseMsgEnd _proxy
Prelude.return _result
unimplemented ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Thrift.ThriftM p c s ()
unimplemented
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift (unimplementedIO _proxy _channel _counter _opts)
unimplementedIO ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s -> Thrift.Counter -> Thrift.RpcOptions -> Prelude.IO ()
unimplementedIO _proxy _channel _counter _opts
= do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
(recv_unimplemented _proxy)
send_unimplemented _proxy _channel _counter _sendCob _recvCob _opts
Thrift.wait _handle
send_unimplemented ::
(Thrift.Protocol p, Thrift.ClientChannel c,
(Thrift.<:) s Calculator) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RecvCallback -> Thrift.RpcOptions -> Prelude.IO ()
send_unimplemented _proxy _channel _counter _sendCob _recvCob
_rpcOpts
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString (_build_unimplemented _proxy _seqNum))
Thrift.sendRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_recvCob
recv_unimplemented ::
(Thrift.Protocol p) =>
Proxy.Proxy p ->
Thrift.Response -> Prelude.Either Exception.SomeException ()
recv_unimplemented _proxy (Thrift.Response _response _)
= Monad.join
(Arrow.left (Exception.SomeException . Thrift.ProtocolException)
(Parser.parse (_parse_unimplemented _proxy) _response))
_build_unimplemented ::
Thrift.Protocol p =>
Proxy.Proxy p -> Int.Int32 -> ByteString.Builder
_build_unimplemented _proxy _seqNum
= Thrift.genMsgBegin _proxy "unimplemented" 1 _seqNum <>
Thrift.genStruct _proxy []
<> Thrift.genMsgEnd _proxy
_parse_unimplemented ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Parser.Parser (Prelude.Either Exception.SomeException ())
_parse_unimplemented _proxy
= do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
_result <- case _msgTy of
1 -> Prelude.fail
"unimplemented: expected reply but got function call"
2 | _name == "unimplemented" ->
do let
_idMap = HashMap.fromList []
_fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
case _fieldBegin of
Thrift.FieldBegin _type _id _bool -> do case _id of
_ -> Prelude.fail
(Prelude.unwords
["unrecognized exception, type:",
Prelude.show
_type,
"field id:",
Prelude.show _id])
Thrift.FieldEnd -> Prelude.return (Prelude.Right ())
| Prelude.otherwise -> Prelude.fail "reply function does not match"
3 -> Prelude.fmap (Prelude.Left . Exception.SomeException)
(Thrift.parseStruct _proxy ::
Parser.Parser Thrift.ApplicationException)
4 -> Prelude.fail
"unimplemented: expected reply but got oneway function call"
_ -> Prelude.fail "unimplemented: invalid message type"
Thrift.parseMsgEnd _proxy
Prelude.return _result