----------------------------------------------------------------- -- 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 GADTs #-} module Math.Calculator.Service (CalculatorCommand(..), reqName', reqParser', respWriter', methodsInfo') where import qualified Control.Exception as Exception import qualified Control.Monad.ST.Trans as ST import qualified Control.Monad.Trans.Class as Trans import qualified Data.ByteString.Builder as Builder import qualified Data.Default as Default import qualified Data.HashMap.Strict as HashMap import qualified Data.Int as Int import qualified Data.Map.Strict as Map import qualified Data.Proxy as Proxy import qualified Data.Text as Text import qualified Math.Adder.Service as Adder import qualified Math.Types as Types import qualified Prelude as Prelude import qualified Thrift.Binary.Parser as Parser import qualified Thrift.Codegen as Thrift import qualified Thrift.Processor as Thrift import qualified Thrift.Protocol.ApplicationException.Types as Thrift import Control.Applicative ((<*), (*>)) import Data.Monoid ((<>)) import Prelude ((<$>), (<*>), (++), (.), (==)) data CalculatorCommand a where Divide :: Prelude.Double -> Prelude.Double -> CalculatorCommand Prelude.Double QuotRem :: Prelude.Int -> Prelude.Int -> CalculatorCommand Types.QuotRemResponse Put :: Prelude.Int -> CalculatorCommand () PutMany :: [Prelude.Int] -> CalculatorCommand () Get :: CalculatorCommand Prelude.Int Unimplemented :: CalculatorCommand () SuperAdder :: Adder.AdderCommand a -> CalculatorCommand a instance Thrift.Processor CalculatorCommand where reqName = reqName' reqParser = reqParser' respWriter = respWriter' methodsInfo _ = methodsInfo' reqName' :: CalculatorCommand a -> Text.Text reqName' (Divide __field__dividend __field__divisor) = "divide" reqName' (QuotRem __field__dividend __field__divisor) = "quotRem" reqName' (Put __field__val) = "put" reqName' (PutMany __field__val) = "putMany" reqName' Get = "get" reqName' Unimplemented = "unimplemented" reqName' (SuperAdder x) = Adder.reqName' x reqParser' :: Thrift.Protocol p => Proxy.Proxy p -> Text.Text -> Parser.Parser (Thrift.Some CalculatorCommand) reqParser' _proxy "divide" = ST.runSTT (do Prelude.return () __field__dividend <- ST.newSTRef Default.def __field__divisor <- ST.newSTRef Default.def let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of 1 | _type == Thrift.getDoubleType _proxy -> do !_val <- Trans.lift (Thrift.parseDouble _proxy) ST.writeSTRef __field__dividend _val 2 | _type == Thrift.getDoubleType _proxy -> do !_val <- Trans.lift (Thrift.parseDouble _proxy) ST.writeSTRef __field__divisor _val _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do !__val__dividend <- ST.readSTRef __field__dividend !__val__divisor <- ST.readSTRef __field__divisor Prelude.pure (Thrift.Some (Divide __val__dividend __val__divisor)) _idMap = HashMap.fromList [("dividend", 1), ("divisor", 2)] _parse 0) reqParser' _proxy "quotRem" = ST.runSTT (do Prelude.return () __field__dividend <- ST.newSTRef Default.def __field__divisor <- ST.newSTRef Default.def let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of 1 | _type == Thrift.getI64Type _proxy -> do !_val <- Trans.lift (Prelude.fromIntegral <$> Thrift.parseI64 _proxy) ST.writeSTRef __field__dividend _val 2 | _type == Thrift.getI64Type _proxy -> do !_val <- Trans.lift (Prelude.fromIntegral <$> Thrift.parseI64 _proxy) ST.writeSTRef __field__divisor _val _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do !__val__dividend <- ST.readSTRef __field__dividend !__val__divisor <- ST.readSTRef __field__divisor Prelude.pure (Thrift.Some (QuotRem __val__dividend __val__divisor)) _idMap = HashMap.fromList [("dividend", 1), ("divisor", 2)] _parse 0) reqParser' _proxy "put" = ST.runSTT (do Prelude.return () __field__val <- ST.newSTRef Default.def let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of 1 | _type == Thrift.getI64Type _proxy -> do !_val <- Trans.lift (Prelude.fromIntegral <$> Thrift.parseI64 _proxy) ST.writeSTRef __field__val _val _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do !__val__val <- ST.readSTRef __field__val Prelude.pure (Thrift.Some (Put __val__val)) _idMap = HashMap.fromList [("val", 1)] _parse 0) reqParser' _proxy "putMany" = ST.runSTT (do Prelude.return () __field__val <- ST.newSTRef Default.def let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of 1 | _type == Thrift.getListType _proxy -> do !_val <- Trans.lift (Prelude.snd <$> Thrift.parseList _proxy (Prelude.fromIntegral <$> Thrift.parseI64 _proxy)) ST.writeSTRef __field__val _val _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do !__val__val <- ST.readSTRef __field__val Prelude.pure (Thrift.Some (PutMany __val__val)) _idMap = HashMap.fromList [("val", 1)] _parse 0) reqParser' _proxy "get" = ST.runSTT (do Prelude.return () let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do Prelude.pure (Thrift.Some Get) _idMap = HashMap.fromList [] _parse 0) reqParser' _proxy "unimplemented" = ST.runSTT (do Prelude.return () let _parse _lastId = do _fieldBegin <- Trans.lift (Thrift.parseFieldBegin _proxy _lastId _idMap) case _fieldBegin of Thrift.FieldBegin _type _id _bool -> do case _id of _ -> Trans.lift (Thrift.parseSkip _proxy _type (Prelude.Just _bool)) _parse _id Thrift.FieldEnd -> do Prelude.pure (Thrift.Some Unimplemented) _idMap = HashMap.fromList [] _parse 0) reqParser' _proxy funName = do Thrift.Some x <- Adder.reqParser' _proxy funName Prelude.return (Thrift.Some (SuperAdder x)) respWriter' :: Thrift.Protocol p => Proxy.Proxy p -> Int.Int32 -> CalculatorCommand a -> Prelude.Either Exception.SomeException a -> (Builder.Builder, Prelude.Maybe (Exception.SomeException, Thrift.Blame)) respWriter' _proxy _seqNum Divide{} _r = (Thrift.genMsgBegin _proxy "divide" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.Just _e@Types.DivideByZero{} <- Exception.fromException _ex -> (2, Thrift.genStruct _proxy [Thrift.genField _proxy "divisionError" (Thrift.getStructType _proxy) 1 0 (Thrift.buildStruct _proxy _e)], Prelude.Just (_ex, Thrift.ClientError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [Thrift.genField _proxy "" (Thrift.getDoubleType _proxy) 0 0 (Thrift.genDouble _proxy _result)], Prelude.Nothing) respWriter' _proxy _seqNum QuotRem{} _r = (Thrift.genMsgBegin _proxy "quotRem" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [Thrift.genField _proxy "" (Thrift.getStructType _proxy) 0 0 (Thrift.buildStruct _proxy _result)], Prelude.Nothing) respWriter' _proxy _seqNum Put{} _r = (Thrift.genMsgBegin _proxy "put" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [], Prelude.Nothing) respWriter' _proxy _seqNum PutMany{} _r = (Thrift.genMsgBegin _proxy "putMany" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [], Prelude.Nothing) respWriter' _proxy _seqNum Get{} _r = (Thrift.genMsgBegin _proxy "get" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [Thrift.genField _proxy "" (Thrift.getI64Type _proxy) 0 0 ((Thrift.genI64 _proxy . Prelude.fromIntegral) _result)], Prelude.Nothing) respWriter' _proxy _seqNum Unimplemented{} _r = (Thrift.genMsgBegin _proxy "unimplemented" _msgType _seqNum <> _msgBody <> Thrift.genMsgEnd _proxy, _msgException) where (_msgType, _msgBody, _msgException) = case _r of Prelude.Left _ex | Prelude.Just _e@Thrift.ApplicationException{} <- Exception.fromException _ex -> (3, Thrift.buildStruct _proxy _e, Prelude.Just (_ex, Thrift.ServerError)) | Prelude.otherwise -> let _e = Thrift.ApplicationException (Text.pack (Prelude.show _ex)) Thrift.ApplicationExceptionType_InternalError in (3, Thrift.buildStruct _proxy _e, Prelude.Just (Exception.toException _e, Thrift.ServerError)) Prelude.Right _result -> (2, Thrift.genStruct _proxy [], Prelude.Nothing) respWriter' _proxy _seqNum (SuperAdder _x) _r = Adder.respWriter' _proxy _seqNum _x _r methodsInfo' :: Map.Map Text.Text Thrift.MethodInfo methodsInfo' = Map.union (Map.fromList [("divide", Thrift.MethodInfo Thrift.NormalPriority Prelude.False), ("quotRem", Thrift.MethodInfo Thrift.NormalPriority Prelude.False), ("put", Thrift.MethodInfo Thrift.NormalPriority Prelude.True), ("putMany", Thrift.MethodInfo Thrift.NormalPriority Prelude.True), ("get", Thrift.MethodInfo Thrift.NormalPriority Prelude.False), ("unimplemented", Thrift.MethodInfo Thrift.NormalPriority Prelude.False)]) Adder.methodsInfo'