service.grpc.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: service.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 GRPC
  23. import NIO
  24. /// Usage: instantiate Codegentest_FooClient, then call methods of this protocol to make API calls.
  25. internal protocol Codegentest_FooClientProtocol: GRPCClient {
  26. func get(
  27. _ request: Codegentest_FooMessage,
  28. callOptions: CallOptions?
  29. ) -> UnaryCall<Codegentest_FooMessage, Codegentest_FooMessage>
  30. }
  31. extension Codegentest_FooClientProtocol {
  32. /// Unary call to Get
  33. ///
  34. /// - Parameters:
  35. /// - request: Request to send to Get.
  36. /// - callOptions: Call options.
  37. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  38. internal func get(
  39. _ request: Codegentest_FooMessage,
  40. callOptions: CallOptions? = nil
  41. ) -> UnaryCall<Codegentest_FooMessage, Codegentest_FooMessage> {
  42. return self.makeUnaryCall(
  43. path: "/codegentest.Foo/Get",
  44. request: request,
  45. callOptions: callOptions ?? self.defaultCallOptions
  46. )
  47. }
  48. }
  49. internal final class Codegentest_FooClient: Codegentest_FooClientProtocol {
  50. internal let channel: GRPCChannel
  51. internal var defaultCallOptions: CallOptions
  52. /// Creates a client for the codegentest.Foo service.
  53. ///
  54. /// - Parameters:
  55. /// - channel: `GRPCChannel` to the service host.
  56. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  57. internal init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  58. self.channel = channel
  59. self.defaultCallOptions = defaultCallOptions
  60. }
  61. }
  62. /// To build a server, implement a class that conforms to this protocol.
  63. internal protocol Codegentest_FooProvider: CallHandlerProvider {
  64. func get(request: Codegentest_FooMessage, context: StatusOnlyCallContext) -> EventLoopFuture<Codegentest_FooMessage>
  65. }
  66. extension Codegentest_FooProvider {
  67. internal var serviceName: Substring { return "codegentest.Foo" }
  68. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  69. /// Returns nil for methods not handled by this service.
  70. internal func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  71. switch methodName {
  72. case "Get":
  73. return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
  74. return { request in
  75. self.get(request: request, context: context)
  76. }
  77. }
  78. default: return nil
  79. }
  80. }
  81. }