Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
---- Licensed to the Apache Software Foundation (ASF) under one-- or more contributor license agreements. See the NOTICE file-- distributed with this work for additional information-- regarding copyright ownership. The ASF licenses this file-- to you under the Apache License, Version 2.0 (the-- "License"); you may not use this file except in compliance-- with the License. You may obtain a copy of the License at---- http://www.apache.org/licenses/LICENSE-2.0---- Unless required by applicable law or agreed to in writing,-- software distributed under the License is distributed on an-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY-- KIND, either express or implied. See the License for the-- specific language governing permissions and limitations-- under the License.--module Thrift( module Thrift.Transport, module Thrift.Protocol, AppExnType(..), AppExn(..), readAppExn, writeAppExn, ThriftException(..)) whereimport Control.Monad ( when )import Control.Exceptionimport Data.Typeable ( Typeable )import Thrift.Transportimport Thrift.Protocoldata ThriftException = ThriftExceptionderiving ( Show, Typeable )instance Exception ThriftExceptiondata AppExnType= AE_UNKNOWN| AE_UNKNOWN_METHOD| AE_INVALID_MESSAGE_TYPE| AE_WRONG_METHOD_NAME| AE_BAD_SEQUENCE_ID| AE_MISSING_RESULTderiving ( Eq, Show, Typeable )instance Enum AppExnType wheretoEnum 0 = AE_UNKNOWNtoEnum 1 = AE_UNKNOWN_METHODtoEnum 2 = AE_INVALID_MESSAGE_TYPEtoEnum 3 = AE_WRONG_METHOD_NAMEtoEnum 4 = AE_BAD_SEQUENCE_IDtoEnum 5 = AE_MISSING_RESULTfromEnum AE_UNKNOWN = 0fromEnum AE_UNKNOWN_METHOD = 1fromEnum AE_INVALID_MESSAGE_TYPE = 2fromEnum AE_WRONG_METHOD_NAME = 3fromEnum AE_BAD_SEQUENCE_ID = 4fromEnum AE_MISSING_RESULT = 5data AppExn = AppExn { ae_type :: AppExnType, ae_message :: String }deriving ( Show, Typeable )instance Exception AppExnwriteAppExn :: (Protocol p, Transport t) => p t -> AppExn -> IO ()writeAppExn pt ae = dowriteStructBegin pt "TApplicationException"when (ae_message ae /= "") $ dowriteFieldBegin pt ("message", T_STRING , 1)writeString pt (ae_message ae)writeFieldEnd ptwriteFieldBegin pt ("type", T_I32, 2);writeI32 pt (fromEnum (ae_type ae))writeFieldEnd ptwriteFieldStop ptwriteStructEnd ptreadAppExn :: (Protocol p, Transport t) => p t -> IO AppExnreadAppExn pt = doreadStructBegin ptrec <- readAppExnFields pt (AppExn {ae_type = undefined, ae_message = undefined})readStructEnd ptreturn recreadAppExnFields pt rec = do(n, ft, id) <- readFieldBegin ptif ft == T_STOPthen return recelse case id of1 -> if ft == T_STRING thendo s <- readString ptreadAppExnFields pt rec{ae_message = s}else do skip pt ftreadAppExnFields pt rec2 -> if ft == T_I32 thendo i <- readI32 ptreadAppExnFields pt rec{ae_type = (toEnum i)}else do skip pt ftreadAppExnFields pt rec_ -> do skip pt ftreadFieldEnd ptreadAppExnFields pt rec