AWSPayload

public struct AWSPayload
extension AWSPayload: Decodable

Holds a request or response payload. A request payload can be in the form of either a ByteBuffer or a stream function that will supply ByteBuffers to the HTTP client. A response payload only comes in the form of a ByteBuffer

  • construct a payload from a ByteBuffer

    Declaration

    Swift

    public static func byteBuffer(_ buffer: ByteBuffer) -> AWSPayload
  • construct a payload from a stream function. If you supply a size the stream function will be called repeated until you supply the number of bytes specified. If you don’t supply a size the stream function will be called repeatedly until you supply an empty ByteBuffer

    Declaration

    Swift

    public static func stream(
        size: Int? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        stream: @escaping (EventLoop) -> EventLoopFuture<StreamReaderResult>
    ) -> Self
  • construct an empty payload

    Declaration

    Swift

    public static var empty: `Self` { get }
  • Construct a payload from Data

    Declaration

    Swift

    public static func data(_ data: Data, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator()) -> AWSPayload
  • Construct a payload from a String

    Declaration

    Swift

    public static func string(_ string: String, byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator()) -> AWSPayload
  • Construct a stream payload from a NIOFileHandle

    Declaration

    Swift

    public static func fileHandle(
        _ fileHandle: NIOFileHandle,
        offset: Int? = nil,
        size: Int? = nil,
        fileIO: NonBlockingFileIO,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        callback: @escaping (Int) throws -> Void = { _ in }
    ) -> Self

    Parameters

    fileHandle

    NIO file handle

    offset

    optional offset into file. If not set it will use the current position in the file

    size

    size of block to load from file

    fileIO

    NonBlockingFileIO object

    byteBufferAllocator

    ByteBufferAllocator used during request upload

    callback

    Progress callback called during upload

  • Return the size of the payload. If the payload is a stream it is always possible to return a size

    Declaration

    Swift

    public var size: Int? { get }
  • return payload as Data

    Declaration

    Swift

    public func asData() -> Data?
  • return payload as String

    Declaration

    Swift

    public func asString() -> String?
  • return payload as ByteBuffer

    Declaration

    Swift

    public func asByteBuffer() -> ByteBuffer?
  • does payload consist of zero bytes

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Construct a stream payload from an AsynSequence of ByteBuffers

    Declaration

    Swift

    public static func asyncSequence<AsyncSeq>(_ seq: AsyncSeq, size: Int?) -> AWSPayload where AsyncSeq : AsyncSequence, AsyncSeq.Element == ByteBuffer

    Parameters

    seq

    AsyncSequence providing ByteBuffers

    size

    total size of sequence in bytes

  • Declaration

    Swift

    public init(from decoder: Decoder) throws