ClientContext.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2024, 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 context passed to the client containing additional information about the RPC.
  17. @available(gRPCSwift 2.0, *)
  18. public struct ClientContext: Sendable {
  19. /// A description of the method being called.
  20. public var descriptor: MethodDescriptor
  21. /// A description of the remote peer.
  22. ///
  23. /// The format of the description should follow the pattern "<transport>:<address>" where
  24. /// "<transport>" indicates the underlying network transport (such as "ipv4", "unix", or
  25. /// "in-process"). This is a guideline for how descriptions should be formatted; different
  26. /// implementations may not follow this format so you shouldn't make assumptions based on it.
  27. ///
  28. /// Some examples include:
  29. /// - "ipv4:127.0.0.1:31415",
  30. /// - "ipv6:[::1]:443",
  31. /// - "in-process:27182".
  32. public var remotePeer: String
  33. /// A description of the local peer.
  34. ///
  35. /// The format of the description should follow the pattern "<transport>:<address>" where
  36. /// "<transport>" indicates the underlying network transport (such as "ipv4", "unix", or
  37. /// "in-process"). This is a guideline for how descriptions should be formatted; different
  38. /// implementations may not follow this format so you shouldn't make assumptions based on it.
  39. ///
  40. /// Some examples include:
  41. /// - "ipv4:127.0.0.1:31415",
  42. /// - "ipv6:[::1]:443",
  43. /// - "in-process:27182".
  44. public var localPeer: String
  45. /// Create a new client interceptor context.
  46. ///
  47. /// - Parameters:
  48. /// - descriptor: A description of the method being called.
  49. /// - remotePeer: A description of the remote peer.
  50. /// - localPeer: A description of the local peer.
  51. public init(
  52. descriptor: MethodDescriptor,
  53. remotePeer: String,
  54. localPeer: String
  55. ) {
  56. self.descriptor = descriptor
  57. self.remotePeer = remotePeer
  58. self.localPeer = localPeer
  59. }
  60. }