@@ -92,10 +92,7 @@ public extension EventLoopLambdaHandler where In: Decodable {
92
92
/// Implementation of `Out` to `ByteBuffer` encoding
93
93
public extension EventLoopLambdaHandler where Out: Encodable {
94
94
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)
99
96
}
100
97
}
101
98
@@ -120,7 +117,7 @@ public protocol LambdaCodableDecoder {
120
117
}
121
118
122
119
public 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
124
121
}
125
122
126
123
private extension Lambda {
@@ -129,4 +126,11 @@ private extension Lambda {
129
126
}
130
127
131
128
extension 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