packages feed

thrift-compiler-0.1.0.1: test/fixtures/gen-hs2/A/S/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 A.S.Client
       (S, getNumber, getNumberIO, send_getNumber, _build_getNumber,
        recv_getNumber, _parse_getNumber, doNothing, doNothingIO,
        send_doNothing, _build_doNothing, recv_doNothing, _parse_doNothing)
       where
import qualified B.Types as B
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 A.Types

data S

getNumber ::
            (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
            Int.Int32 -> Thrift.ThriftM p c s B.Number
getNumber __field__x
  = do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
       Trans.lift (getNumberIO _proxy _channel _counter _opts __field__x)

getNumberIO ::
              (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
              Proxy.Proxy p ->
                c s ->
                  Thrift.Counter ->
                    Thrift.RpcOptions -> Int.Int32 -> Prelude.IO B.Number
getNumberIO _proxy _channel _counter _opts __field__x
  = do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
                                          (recv_getNumber _proxy)
       send_getNumber _proxy _channel _counter _sendCob _recvCob _opts
         __field__x
       Thrift.wait _handle

send_getNumber ::
                 (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
                 Proxy.Proxy p ->
                   c s ->
                     Thrift.Counter ->
                       Thrift.SendCallback ->
                         Thrift.RecvCallback ->
                           Thrift.RpcOptions -> Int.Int32 -> Prelude.IO ()
send_getNumber _proxy _channel _counter _sendCob _recvCob _rpcOpts
  __field__x
  = do _seqNum <- _counter
       let
         _callMsg
           = LBS.toStrict
               (ByteString.toLazyByteString
                  (_build_getNumber _proxy _seqNum __field__x))
       Thrift.sendRequest _channel
         (Thrift.Request _callMsg
            (Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
         _sendCob
         _recvCob

recv_getNumber ::
                 (Thrift.Protocol p) =>
                 Proxy.Proxy p ->
                   Thrift.Response -> Prelude.Either Exception.SomeException B.Number
recv_getNumber _proxy (Thrift.Response _response _)
  = Monad.join
      (Arrow.left (Exception.SomeException . Thrift.ProtocolException)
         (Parser.parse (_parse_getNumber _proxy) _response))

_build_getNumber ::
                   Thrift.Protocol p =>
                   Proxy.Proxy p -> Int.Int32 -> Int.Int32 -> ByteString.Builder
_build_getNumber _proxy _seqNum __field__x
  = Thrift.genMsgBegin _proxy "getNumber" 1 _seqNum <>
      Thrift.genStruct _proxy
        (Thrift.genFieldPrim _proxy "x" (Thrift.getI32Type _proxy) 1 0
           (Thrift.genI32Prim _proxy)
           __field__x
           : [])
      <> Thrift.genMsgEnd _proxy

_parse_getNumber ::
                   Thrift.Protocol p =>
                   Proxy.Proxy p ->
                     Parser.Parser (Prelude.Either Exception.SomeException B.Number)
_parse_getNumber _proxy
  = do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
       _result <- case _msgTy of
                    1 -> Prelude.fail "getNumber: expected reply but got function call"
                    2 | _name == "getNumber" ->
                        do let
                             _idMap = HashMap.fromList [("getNumber_success", 0)]
                           _fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
                           case _fieldBegin of
                             Thrift.FieldBegin _type _id _bool -> do case _id of
                                                                       0 | _type ==
                                                                             Thrift.getI32Type
                                                                               _proxy
                                                                           ->
                                                                           Prelude.fmap
                                                                             Prelude.Right
                                                                             (Thrift.parseEnum
                                                                                _proxy
                                                                                "Number")
                                                                       _ -> 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
                           "getNumber: expected reply but got oneway function call"
                    _ -> Prelude.fail "getNumber: invalid message type"
       Thrift.parseMsgEnd _proxy
       Prelude.return _result

doNothing ::
            (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
            Thrift.ThriftM p c s ()
doNothing
  = do Thrift.ThriftEnv _proxy _channel _opts _counter <- Reader.ask
       Trans.lift (doNothingIO _proxy _channel _counter _opts)

doNothingIO ::
              (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
              Proxy.Proxy p ->
                c s -> Thrift.Counter -> Thrift.RpcOptions -> Prelude.IO ()
doNothingIO _proxy _channel _counter _opts
  = do (_handle, _sendCob, _recvCob) <- Thrift.mkCallbacks
                                          (recv_doNothing _proxy)
       send_doNothing _proxy _channel _counter _sendCob _recvCob _opts
       Thrift.wait _handle

send_doNothing ::
                 (Thrift.Protocol p, Thrift.ClientChannel c, (Thrift.<:) s S) =>
                 Proxy.Proxy p ->
                   c s ->
                     Thrift.Counter ->
                       Thrift.SendCallback ->
                         Thrift.RecvCallback -> Thrift.RpcOptions -> Prelude.IO ()
send_doNothing _proxy _channel _counter _sendCob _recvCob _rpcOpts
  = do _seqNum <- _counter
       let
         _callMsg
           = LBS.toStrict
               (ByteString.toLazyByteString (_build_doNothing _proxy _seqNum))
       Thrift.sendRequest _channel
         (Thrift.Request _callMsg
            (Thrift.setRpcPriority _rpcOpts Thrift.NormalPriority))
         _sendCob
         _recvCob

recv_doNothing ::
                 (Thrift.Protocol p) =>
                 Proxy.Proxy p ->
                   Thrift.Response -> Prelude.Either Exception.SomeException ()
recv_doNothing _proxy (Thrift.Response _response _)
  = Monad.join
      (Arrow.left (Exception.SomeException . Thrift.ProtocolException)
         (Parser.parse (_parse_doNothing _proxy) _response))

_build_doNothing ::
                   Thrift.Protocol p =>
                   Proxy.Proxy p -> Int.Int32 -> ByteString.Builder
_build_doNothing _proxy _seqNum
  = Thrift.genMsgBegin _proxy "doNothing" 1 _seqNum <>
      Thrift.genStruct _proxy []
      <> Thrift.genMsgEnd _proxy

_parse_doNothing ::
                   Thrift.Protocol p =>
                   Proxy.Proxy p ->
                     Parser.Parser (Prelude.Either Exception.SomeException ())
_parse_doNothing _proxy
  = do Thrift.MsgBegin _name _msgTy _ <- Thrift.parseMsgBegin _proxy
       _result <- case _msgTy of
                    1 -> Prelude.fail "doNothing: expected reply but got function call"
                    2 | _name == "doNothing" ->
                        do let
                             _idMap = HashMap.fromList [("ex", 1)]
                           _fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
                           case _fieldBegin of
                             Thrift.FieldBegin _type _id _bool -> do case _id of
                                                                       1 | _type ==
                                                                             Thrift.getStructType
                                                                               _proxy
                                                                           ->
                                                                           Prelude.fmap
                                                                             (Prelude.Left .
                                                                                Exception.SomeException)
                                                                             (Thrift.parseStruct
                                                                                _proxy
                                                                                :: Parser.Parser X)
                                                                       _ -> 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
                           "doNothing: expected reply but got oneway function call"
                    _ -> Prelude.fail "doNothing: invalid message type"
       Thrift.parseMsgEnd _proxy
       Prelude.return _result