echo_nio.grpc.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /// To build a server, implement a class that conforms to this protocol.
  28. internal protocol Echo_EchoProvider_NIO: CallHandlerProvider {
  29. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  30. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  31. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  32. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  33. }
  34. extension Echo_EchoProvider_NIO {
  35. internal var serviceName: String { return "echo.Echo" }
  36. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  37. /// Returns nil for methods not handled by this service.
  38. internal func handleMethod(_ methodName: String, request: HTTPRequestHead, serverHandler: GRPCChannelHandler, channel: Channel, errorDelegate: ServerErrorDelegate?) -> GRPCCallHandler? {
  39. switch methodName {
  40. case "Get":
  41. return UnaryCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  42. return { request in
  43. self.get(request: request, context: context)
  44. }
  45. }
  46. case "Expand":
  47. return ServerStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  48. return { request in
  49. self.expand(request: request, context: context)
  50. }
  51. }
  52. case "Collect":
  53. return ClientStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  54. return self.collect(context: context)
  55. }
  56. case "Update":
  57. return BidirectionalStreamingCallHandler(channel: channel, request: request, errorDelegate: errorDelegate) { context in
  58. return self.update(context: context)
  59. }
  60. default: return nil
  61. }
  62. }
  63. }