MethodDescriptor.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2023, 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. /// A description of a method on a service.
  17. @available(gRPCSwift 2.0, *)
  18. public struct MethodDescriptor: Sendable, Hashable {
  19. /// A description of the service, including its package name.
  20. public var service: ServiceDescriptor
  21. /// The name of the method in the service, excluding the service name.
  22. public var method: String
  23. /// The fully qualified method name in the format "package.service/method".
  24. ///
  25. /// For example, the fully qualified name of the "SayHello" method of the "Greeter" service in
  26. /// "helloworld" package is "helloworld.Greeter/SayHelllo".
  27. public var fullyQualifiedMethod: String {
  28. "\(self.service)/\(self.method)"
  29. }
  30. /// Creates a new method descriptor.
  31. ///
  32. /// - Parameters:
  33. /// - service: The name of the service, including the package name. For example,
  34. /// "helloworld.Greeter".
  35. /// - method: The name of the method. For example, "SayHello".
  36. public init(service: ServiceDescriptor, method: String) {
  37. self.service = service
  38. self.method = method
  39. }
  40. /// Creates a new method descriptor.
  41. ///
  42. /// - Parameters:
  43. /// - fullyQualifiedService: The fully qualified name of the service, including the package
  44. /// name. For example, "helloworld.Greeter".
  45. /// - method: The name of the method. For example, "SayHello".
  46. public init(fullyQualifiedService: String, method: String) {
  47. self.service = ServiceDescriptor(fullyQualifiedService: fullyQualifiedService)
  48. self.method = method
  49. }
  50. }
  51. @available(gRPCSwift 2.0, *)
  52. extension MethodDescriptor: CustomStringConvertible {
  53. public var description: String {
  54. self.fullyQualifiedMethod
  55. }
  56. }