GRPCPayload.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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 NIO
  17. /// Data passed through the library is required to conform to this GRPCPayload protocol
  18. public protocol GRPCPayload {
  19. /// Initializes a new payload object from a given `NIO.ByteBuffer`
  20. ///
  21. /// - Parameter serializedByteBuffer: A buffer containing the serialised bytes of this payload.
  22. /// - Throws: Should throw an error if the data wasn't serialized properly
  23. init(serializedByteBuffer: inout NIO.ByteBuffer) throws
  24. /// Serializes the payload into a `ByteBuffer`.
  25. ///
  26. /// - Parameters:
  27. /// - buffer: The buffer to write the payload into.
  28. /// - Note: Implementers must *NOT* clear or read bytes from `buffer`.
  29. func serialize(into buffer: inout NIO.ByteBuffer) throws
  30. }