ClientContext.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. public init(
  46. descriptor: MethodDescriptor,
  47. remotePeer: String,
  48. localPeer: String
  49. ) {
  50. self.descriptor = descriptor
  51. self.remotePeer = remotePeer
  52. self.localPeer = localPeer
  53. }
  54. }