echo.grpc.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: echo.proto
  6. //
  7. //
  8. // Copyright 2018, gRPC Authors All rights reserved.
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. //
  22. import Foundation
  23. import NIO
  24. import NIOHTTP1
  25. import SwiftGRPCNIO
  26. import SwiftProtobuf
  27. /// Usage: instantiate Echo_EchoService_NIOClient, then call methods of this protocol to make API calls.
  28. internal protocol Echo_EchoService_NIO {
  29. func get(_ request: Echo_EchoRequest, callOptions: CallOptions?) -> UnaryClientCall<Echo_EchoRequest, Echo_EchoResponse>
  30. func expand(_ request: Echo_EchoRequest, callOptions: CallOptions?, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse>
  31. func collect(callOptions: CallOptions?) -> ClientStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse>
  32. func update(callOptions: CallOptions?, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse>
  33. }
  34. internal final class Echo_EchoService_NIOClient: GRPCServiceClient, Echo_EchoService_NIO {
  35. internal let client: GRPCClient
  36. internal let service = "echo.Echo"
  37. internal var defaultCallOptions: CallOptions
  38. /// Creates a client for the echo.Echo service.
  39. ///
  40. /// - Parameters:
  41. /// - client: `GRPCClient` with a connection to the service host.
  42. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. Defaults to `client.defaultCallOptions`.
  43. internal init(client: GRPCClient, defaultCallOptions: CallOptions? = nil) {
  44. self.client = client
  45. self.defaultCallOptions = defaultCallOptions ?? client.defaultCallOptions
  46. }
  47. /// Asynchronous unary call to Get.
  48. ///
  49. /// - Parameters:
  50. /// - request: Request to send to Get.
  51. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  52. /// - Returns: A `UnaryClientCall` with futures for the metadata, status and response.
  53. internal func get(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryClientCall<Echo_EchoRequest, Echo_EchoResponse> {
  54. return UnaryClientCall(client: client, path: path(forMethod: "Get"), request: request, callOptions: callOptions ?? self.defaultCallOptions)
  55. }
  56. /// Asynchronous server-streaming call to Expand.
  57. ///
  58. /// - Parameters:
  59. /// - request: Request to send to Expand.
  60. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  61. /// - handler: A closure called when each response is received from the server.
  62. /// - Returns: A `ServerStreamingClientCall` with futures for the metadata and status.
  63. internal func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse> {
  64. return ServerStreamingClientCall(client: client, path: path(forMethod: "Expand"), request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler)
  65. }
  66. /// Asynchronous client-streaming call to Collect.
  67. ///
  68. /// Callers should use the `send` method on the returned object to send messages
  69. /// to the server. The caller should send an `.end` after the final message has been sent.
  70. ///
  71. /// - Parameters:
  72. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  73. /// - Returns: A `ClientStreamingClientCall` with futures for the metadata, status and response.
  74. internal func collect(callOptions: CallOptions? = nil) -> ClientStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse> {
  75. return ClientStreamingClientCall(client: client, path: path(forMethod: "Collect"), callOptions: callOptions ?? self.defaultCallOptions)
  76. }
  77. /// Asynchronous bidirectional-streaming call to Update.
  78. ///
  79. /// Callers should use the `send` method on the returned object to send messages
  80. /// to the server. The caller should send an `.end` after the final message has been sent.
  81. ///
  82. /// - Parameters:
  83. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  84. /// - handler: A closure called when each response is received from the server.
  85. /// - Returns: A `ClientStreamingClientCall` with futures for the metadata and status.
  86. internal func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingClientCall<Echo_EchoRequest, Echo_EchoResponse> {
  87. return BidirectionalStreamingClientCall(client: client, path: path(forMethod: "Update"), callOptions: callOptions ?? self.defaultCallOptions, handler: handler)
  88. }
  89. }
  90. /// To build a server, implement a class that conforms to this protocol.
  91. internal protocol Echo_EchoProvider_NIO: CallHandlerProvider {
  92. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  93. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  94. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  95. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  96. }
  97. extension Echo_EchoProvider_NIO {
  98. internal var serviceName: String { return "echo.Echo" }
  99. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  100. /// Returns nil for methods not handled by this service.
  101. internal func handleMethod(_ methodName: String, request: HTTPRequestHead, serverHandler: GRPCChannelHandler, channel: Channel, errorDelegate: ServerErrorDelegate?) -> GRPCCallHandler? {
  102. switch methodName {
  103. case "Get":
  104. return UnaryCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  105. return { request in
  106. self.get(request: request, context: context)
  107. }
  108. }
  109. case "Expand":
  110. return ServerStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  111. return { request in
  112. self.expand(request: request, context: context)
  113. }
  114. }
  115. case "Collect":
  116. return ClientStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  117. return self.collect(context: context)
  118. }
  119. case "Update":
  120. return BidirectionalStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  121. return self.update(context: context)
  122. }
  123. default: return nil
  124. }
  125. }
  126. }