GRPCChannel.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2020, 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. import NIO
  17. import NIOHTTP2
  18. import NIOSSL
  19. import SwiftProtobuf
  20. public protocol GRPCChannel {
  21. /// Make a unary gRPC call.
  22. ///
  23. /// - Parameters:
  24. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  25. /// - request: The request to send.
  26. /// - callOptions: Options for the RPC.
  27. func makeUnaryCall<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>(
  28. path: String,
  29. request: Request,
  30. callOptions: CallOptions
  31. ) -> UnaryCall<Request, Response>
  32. /// Make a unary gRPC call.
  33. ///
  34. /// - Parameters:
  35. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  36. /// - request: The request to send.
  37. /// - callOptions: Options for the RPC.
  38. func makeUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
  39. path: String,
  40. request: Request,
  41. callOptions: CallOptions
  42. ) -> UnaryCall<Request, Response>
  43. /// Make a server-streaming gRPC call.
  44. ///
  45. /// - Parameters:
  46. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  47. /// - request: The request to send.
  48. /// - callOptions: Options for the RPC.
  49. /// - handler: Response handler; called for every response received from the server.
  50. func makeServerStreamingCall<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>(
  51. path: String,
  52. request: Request,
  53. callOptions: CallOptions,
  54. handler: @escaping (Response) -> Void
  55. ) -> ServerStreamingCall<Request, Response>
  56. /// Make a server-streaming gRPC call.
  57. ///
  58. /// - Parameters:
  59. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  60. /// - request: The request to send.
  61. /// - callOptions: Options for the RPC.
  62. /// - handler: Response handler; called for every response received from the server.
  63. func makeServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  64. path: String,
  65. request: Request,
  66. callOptions: CallOptions,
  67. handler: @escaping (Response) -> Void
  68. ) -> ServerStreamingCall<Request, Response>
  69. /// Makes a client-streaming gRPC call.
  70. ///
  71. /// - Parameters:
  72. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  73. /// - callOptions: Options for the RPC.
  74. func makeClientStreamingCall<Request: SwiftProtobuf.Message, Response: SwiftProtobuf.Message>(
  75. path: String,
  76. callOptions: CallOptions
  77. ) -> ClientStreamingCall<Request, Response>
  78. /// Makes a client-streaming gRPC call.
  79. ///
  80. /// - Parameters:
  81. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  82. /// - callOptions: Options for the RPC.
  83. func makeClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  84. path: String,
  85. callOptions: CallOptions
  86. ) -> ClientStreamingCall<Request, Response>
  87. /// Makes a bidirectional-streaming gRPC call.
  88. ///
  89. /// - Parameters:
  90. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  91. /// - callOptions: Options for the RPC.
  92. /// - handler: Response handler; called for every response received from the server.
  93. func makeBidirectionalStreamingCall<
  94. Request: SwiftProtobuf.Message,
  95. Response: SwiftProtobuf.Message
  96. >(
  97. path: String,
  98. callOptions: CallOptions,
  99. handler: @escaping (Response) -> Void
  100. ) -> BidirectionalStreamingCall<Request, Response>
  101. /// Makes a bidirectional-streaming gRPC call.
  102. ///
  103. /// - Parameters:
  104. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  105. /// - callOptions: Options for the RPC.
  106. /// - handler: Response handler; called for every response received from the server.
  107. func makeBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  108. path: String,
  109. callOptions: CallOptions,
  110. handler: @escaping (Response) -> Void
  111. ) -> BidirectionalStreamingCall<Request, Response>
  112. /// Close the channel, and any connections associated with it.
  113. func close() -> EventLoopFuture<Void>
  114. }