/* * Copyright 2016, gRPC Authors All rights reserved. * * Licensed 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. */ #if SWIFT_PACKAGE import CgRPC import Dispatch #endif import Foundation public enum CallError: Error { case ok case unknown case notOnServer case notOnClient case alreadyAccepted case alreadyInvoked case notInvoked case alreadyFinished case tooManyOperations case invalidFlags case invalidMetadata case invalidMessage case notServerCompletionQueue case batchTooBig case payloadTypeMismatch case completionQueueShutdown static func callError(grpcCallError error: grpc_call_error) -> CallError { switch error { case GRPC_CALL_OK: return .ok case GRPC_CALL_ERROR: return .unknown case GRPC_CALL_ERROR_NOT_ON_SERVER: return .notOnServer case GRPC_CALL_ERROR_NOT_ON_CLIENT: return .notOnClient case GRPC_CALL_ERROR_ALREADY_ACCEPTED: return .alreadyAccepted case GRPC_CALL_ERROR_ALREADY_INVOKED: return .alreadyInvoked case GRPC_CALL_ERROR_NOT_INVOKED: return .notInvoked case GRPC_CALL_ERROR_ALREADY_FINISHED: return .alreadyFinished case GRPC_CALL_ERROR_TOO_MANY_OPERATIONS: return .tooManyOperations case GRPC_CALL_ERROR_INVALID_FLAGS: return .invalidFlags case GRPC_CALL_ERROR_INVALID_METADATA: return .invalidMetadata case GRPC_CALL_ERROR_INVALID_MESSAGE: return .invalidMessage case GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE: return .notServerCompletionQueue case GRPC_CALL_ERROR_BATCH_TOO_BIG: return .batchTooBig case GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH: return .payloadTypeMismatch default: return .unknown } } }