@@ -92,10 +92,7 @@ public extension EventLoopLambdaHandler where In: Decodable {
9292/// Implementation of `Out` to `ByteBuffer` encoding
9393public extension EventLoopLambdaHandler where Out: Encodable {
9494 func encode( allocator: ByteBufferAllocator , value: Out ) throws -> ByteBuffer ? {
95- // nio will resize the buffer if necessary
96- var buffer = allocator. buffer ( capacity: 1024 )
97- try self . encoder. encode ( value, into: & buffer)
98- return buffer
95+ try self . encoder. encode ( value, using: allocator)
9996 }
10097}
10198
@@ -120,7 +117,7 @@ public protocol LambdaCodableDecoder {
120117}
121118
122119public protocol LambdaCodableEncoder {
123- func encode< T: Encodable > ( _ value: T , into buffer : inout ByteBuffer ) throws
120+ func encode< T: Encodable > ( _ value: T , using allocator : ByteBufferAllocator ) throws -> ByteBuffer
124121}
125122
126123private extension Lambda {
@@ -129,4 +126,11 @@ private extension Lambda {
129126}
130127
131128extension JSONDecoder : LambdaCodableDecoder { }
132- extension JSONEncoder : LambdaCodableEncoder { }
129+ extension JSONEncoder : LambdaCodableEncoder {
130+ public func encode< T> ( _ value: T , using allocator: ByteBufferAllocator ) throws -> ByteBuffer where T: Encodable {
131+ // nio will resize the buffer if necessary
132+ var buffer = allocator. buffer ( capacity: 1024 )
133+ try self . encode ( value, into: & buffer)
134+ return buffer
135+ }
136+ }
0 commit comments