Skip to content

Instance Method

encode(_:boundary:into:)

Encodes an Encodable item into a ByteBuffer using the supplied boundary.
func encode<E>(_ encodable: E, boundary: String, into buffer: inout ByteBuffer) throws where E : Encodable

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 = ByteBuffer()
let data = try FormDataEncoder().encode(a, boundary: "123", into: &buffer)

Throws

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