GRPCServiceDescription.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2021, 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. public struct GRPCServiceDescriptor: Hashable, Sendable {
  17. /// The name of the service excluding the package, e.g. 'Echo'.
  18. public var name: String
  19. /// The full name of the service including the package, e.g. 'echo.Echo'
  20. public var fullName: String
  21. /// Methods defined on the service.
  22. public var methods: [GRPCMethodDescriptor]
  23. public init(name: String, fullName: String, methods: [GRPCMethodDescriptor]) {
  24. self.name = name
  25. self.fullName = fullName
  26. self.methods = methods
  27. }
  28. }
  29. public struct GRPCMethodDescriptor: Hashable, Sendable {
  30. /// The name of the method, e.g. 'Get'.
  31. public var name: String
  32. /// The full name of the method include the fully qualified name of the service in the
  33. /// format 'package.Service/Method', for example 'echo.Echo/Get'.
  34. ///
  35. /// This differs from the ``path`` only in that the leading '/' is removed.
  36. public var fullName: String {
  37. assert(self.path.utf8.first == UInt8(ascii: "/"))
  38. return String(self.path.dropFirst())
  39. }
  40. /// The path of the method in the format '/package.Service/method', for example '/echo.Echo/Get'.
  41. public var path: String
  42. /// The type of call.
  43. public var type: GRPCCallType
  44. public init(name: String, path: String, type: GRPCCallType) {
  45. self.name = name
  46. self.path = path
  47. self.type = type
  48. }
  49. }