Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Instance Method

encode(_:boundary:into:)

Encodes an Encodable item into some MultipartPartBodyElement using the supplied boundary.
func encode<E, Body>(_ encodable: E, boundary: String, into buffer: inout Body) throws where E : Encodable, Body : RangeReplaceableCollection, Body : Sendable, Body.Element == UInt8

Parameters

encodable

Generic Encodable item.

boundary

Multipart boundary to use for encoding. This must not appear anywhere in the encoded data.

buffer

Buffer to write to.

Discussion

let a = Foo(string: "a", int: 42, double: 3.14, array: [1, 2, 3])
var buffer = ByteBufferView()
let data = try FormDataEncoder().encode(a, boundary: "123", into: &buffer)

Throws

Any errors encoding the model with Codable or serializing the data.