MethodDescriptor.swift 2.6 KB

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