Types.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2021, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. enum Types {
  17. static let serverContext = "GRPCAsyncServerCallContext"
  18. static let serverHandler = "GRPCAsyncServerHandler"
  19. static let clientCallOptions = "CallOptions"
  20. private static let unaryCall = "AsyncUnaryCall"
  21. private static let clientStreamingCall = "AsyncClientStreamingCall"
  22. private static let serverStreamingCall = "AsyncServerStreamingCall"
  23. private static let bidirectionalStreamingCall = "AsyncBidirectionalStreamingCall"
  24. static func requestStream(of type: String) -> String {
  25. return "GRPCAsyncRequestStream<\(type)>"
  26. }
  27. static func responseStream(of type: String) -> String {
  28. return "GRPCAsyncResponseStream<\(type)>"
  29. }
  30. static func responseStreamWriter(of type: String) -> String {
  31. return "GRPCAsyncResponseStreamWriter<\(type)>"
  32. }
  33. static func serializer(for type: String) -> String {
  34. return "ProtobufSerializer<\(type)>"
  35. }
  36. static func deserializer(for type: String) -> String {
  37. return "ProtobufDeserializer<\(type)>"
  38. }
  39. static func call(for streamingType: StreamingType, withGRPCPrefix: Bool = true) -> String {
  40. let typeName: String
  41. switch streamingType {
  42. case .unary:
  43. typeName = Types.unaryCall
  44. case .clientStreaming:
  45. typeName = Types.clientStreamingCall
  46. case .serverStreaming:
  47. typeName = Types.serverStreamingCall
  48. case .bidirectionalStreaming:
  49. typeName = Types.bidirectionalStreamingCall
  50. }
  51. if withGRPCPrefix {
  52. return "GRPC" + typeName
  53. } else {
  54. return typeName
  55. }
  56. }
  57. }