GRPCChannel.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. public protocol GRPCChannel {
  20. /// Make a unary gRPC call.
  21. ///
  22. /// - Parameters:
  23. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  24. /// - request: The request to send.
  25. /// - callOptions: Options for the RPC.
  26. func makeUnaryCall<Request: GRPCPayload, Response: GRPCPayload>(
  27. path: String,
  28. request: Request,
  29. callOptions: CallOptions
  30. ) -> UnaryCall<Request, Response>
  31. /// Make a server-streaming gRPC call.
  32. ///
  33. /// - Parameters:
  34. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  35. /// - request: The request to send.
  36. /// - callOptions: Options for the RPC.
  37. /// - handler: Response handler; called for every response received from the server.
  38. func makeServerStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  39. path: String,
  40. request: Request,
  41. callOptions: CallOptions,
  42. handler: @escaping (Response) -> Void
  43. ) -> ServerStreamingCall<Request, Response>
  44. /// Makes a client-streaming gRPC call.
  45. ///
  46. /// - Parameters:
  47. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  48. /// - callOptions: Options for the RPC.
  49. func makeClientStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  50. path: String,
  51. callOptions: CallOptions
  52. ) -> ClientStreamingCall<Request, Response>
  53. /// Makes a bidirectional-streaming gRPC call.
  54. ///
  55. /// - Parameters:
  56. /// - path: Path of the RPC, e.g. "/echo.Echo/Get"
  57. /// - callOptions: Options for the RPC.
  58. /// - handler: Response handler; called for every response received from the server.
  59. func makeBidirectionalStreamingCall<Request: GRPCPayload, Response: GRPCPayload>(
  60. path: String,
  61. callOptions: CallOptions,
  62. handler: @escaping (Response) -> Void
  63. ) -> BidirectionalStreamingCall<Request, Response>
  64. /// Close the channel, and any connections associated with it.
  65. func close() -> EventLoopFuture<Void>
  66. }