thrift-lib-0.1.0.1: test/gen-hs2/Math/Adder/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.Adder.Client
(Adder, add, addIO, send_add, _build_add, recv_add, _parse_add)
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 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 Adder
add ::
(Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s Adder) =>
Prelude.Int -> Prelude.Int -> Thrift.ThriftM p c s Prelude.Int
add __field__x __field__y
= do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
Trans.lift
(addIO _proxy _channel _counter _opts __field__x __field__y)
addIO ::
(Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s Adder) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.RpcOptions ->
Prelude.Int -> Prelude.Int -> Prelude.IO Prelude.Int
addIO _proxy _channel _counter _opts __field__x __field__y
= do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
(recv_add _proxy)
send_add _proxy _channel _counter _sendCob _recvCob _opts
__field__x
__field__y
Thrift.wait _handle
send_add ::
(Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s Adder) =>
Proxy.Proxy p ->
c s ->
Thrift.Counter ->
Thrift.SendCallback ->
Thrift.RecvCallback ->
Thrift.RpcOptions -> Prelude.Int -> Prelude.Int -> Prelude.IO ()
send_add _proxy _channel _counter _sendCob _recvCob _rpcOpts
__field__x __field__y
= do _seqNum <- _counter
let
_callMsg
= LBS.toStrict
(ByteString.toLazyByteString
(_build_add _proxy _seqNum __field__x __field__y))
Thrift.sendRequest _channel
(Thrift.Request _callMsg
(Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
_sendCob
_recvCob
recv_add ::
(Thrift.Protocol p) =>
Proxy.Proxy p ->
Thrift.Response ->
Prelude.Either Exception.SomeException Prelude.Int
recv_add _proxy (Thrift.Response _response _)
= Monad.join
(Arrow.left (Exception.SomeException . Thrift.ProtocolException)
(Parser.parse (_parse_add _proxy) _response))
_build_add ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Int.Int32 -> Prelude.Int -> Prelude.Int -> ByteString.Builder
_build_add _proxy _seqNum __field__x __field__y
= Thrift.genMsgBegin _proxy "add" 1 _seqNum <>
Thrift.genStruct _proxy
(Thrift.genField _proxy "x" (Thrift.getI64Type _proxy) 1 0
((Thrift.genI64 _proxy . Prelude.fromIntegral) __field__x)
:
Thrift.genField _proxy "y" (Thrift.getI64Type _proxy) 2 1
((Thrift.genI64 _proxy . Prelude.fromIntegral) __field__y)
: [])
<> Thrift.genMsgEnd _proxy
_parse_add ::
Thrift.Protocol p =>
Proxy.Proxy p ->
Parser.Parser (Prelude.Either Exception.SomeException Prelude.Int)
_parse_add _proxy
= do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
_result <- case _msgTy of
1 -> Prelude.fail "add: expected reply but got function call"
2 | _name == "add" ->
do let
_idMap = HashMap.fromList [("add_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
"add: expected reply but got oneway function call"
_ -> Prelude.fail "add: invalid message type"
Thrift.parseMsgEnd _proxy
Prelude.return _result