RPCParts.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// Part of a request sent from a client to a server in a stream.
  17. @available(gRPCSwift 2.0, *)
  18. public enum RPCRequestPart<Bytes: GRPCContiguousBytes> {
  19. /// Key-value pairs sent at the start of a request stream. Only one ``metadata(_:)`` value may
  20. /// be sent to the server.
  21. case metadata(Metadata)
  22. /// The bytes of a serialized message to send to the server. A stream may have any number of
  23. /// messages sent on it. Restrictions for unary request or response streams are imposed at a
  24. /// higher level.
  25. case message(Bytes)
  26. }
  27. @available(gRPCSwift 2.0, *)
  28. extension RPCRequestPart: Sendable where Bytes: Sendable {}
  29. @available(gRPCSwift 2.0, *)
  30. extension RPCRequestPart: Hashable where Bytes: Hashable {}
  31. @available(gRPCSwift 2.0, *)
  32. extension RPCRequestPart: Equatable where Bytes: Equatable {}
  33. /// Part of a response sent from a server to a client in a stream.
  34. @available(gRPCSwift 2.0, *)
  35. public enum RPCResponsePart<Bytes: GRPCContiguousBytes> {
  36. /// Key-value pairs sent at the start of the response stream. At most one ``metadata(_:)`` value
  37. /// may be sent to the client. If the server sends ``metadata(_:)`` it must be the first part in
  38. /// the response stream.
  39. case metadata(Metadata)
  40. /// The bytes of a serialized message to send to the client. A stream may have any number of
  41. /// messages sent on it. Restrictions for unary request or response streams are imposed at a
  42. /// higher level.
  43. case message(Bytes)
  44. /// A status and key-value pairs sent to the client at the end of the response stream. Every
  45. /// response stream must have exactly one ``status(_:_:)`` as the final part of the request
  46. /// stream.
  47. case status(Status, Metadata)
  48. }
  49. @available(gRPCSwift 2.0, *)
  50. extension RPCResponsePart: Sendable where Bytes: Sendable {}
  51. @available(gRPCSwift 2.0, *)
  52. extension RPCResponsePart: Hashable where Bytes: Hashable {}
  53. @available(gRPCSwift 2.0, *)
  54. extension RPCResponsePart: Equatable where Bytes: Equatable {}