ClientContext.swift 2.4 KB

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