ClientParts.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2020, 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. import NIOHPACK
  17. public enum ClientRequestPart<Request> {
  18. /// User provided metadata sent at the start of the request stream.
  19. case metadata(HPACKHeaders)
  20. /// A message to send to the server.
  21. case message(Request, Metadata)
  22. /// End the request stream.
  23. case end
  24. /// Metadata associated with a request message.
  25. public struct Metadata: Equatable {
  26. /// Whether the message should be compressed. If compression has not been enabled on the RPC
  27. /// then setting is ignored.
  28. public var compress: Bool
  29. /// Whether the underlying transported should be 'flushed' after writing this message. If a batch
  30. /// of messages is to be sent then flushing only after the last message may improve
  31. /// performance.
  32. public var flush: Bool
  33. public init(compress: Bool, flush: Bool) {
  34. self.compress = compress
  35. self.flush = flush
  36. }
  37. }
  38. }
  39. public enum ClientResponsePart<Response> {
  40. /// The initial metadata returned by the server.
  41. case metadata(HPACKHeaders)
  42. /// A response message from the server.
  43. case message(Response)
  44. /// The end of response stream sent by the server.
  45. case end(GRPCStatus, HPACKHeaders)
  46. /// Error.
  47. case error(Error)
  48. }