@@ -88,25 +88,30 @@ internal struct CodableVoidLambdaClosureWrapper<In: Decodable>: LambdaHandler {
88
88
public extension EventLoopLambdaHandler where In: Decodable , Out: Encodable {
89
89
func encode( allocator: ByteBufferAllocator , value: Out ) throws -> ByteBuffer ? {
90
90
// nio will resize the buffer if necessary
91
- // FIXME: reusable JSONEncoder and buffer
92
91
var buffer = allocator. buffer ( capacity: 1024 )
93
- try JSONEncoder ( ) . encode ( value, into: & buffer)
92
+ try Lambda . defaultJSONEncoder . encode ( value, into: & buffer)
94
93
return buffer
95
94
}
96
95
97
96
func decode( buffer: ByteBuffer ) throws -> In {
98
- // FIXME: reusable JSONDecoder
99
- try JSONDecoder ( ) . decode ( In . self, from: buffer)
97
+ try Lambda . defaultJSONDecoder. decode ( In . self, from: buffer)
100
98
}
101
99
}
102
100
101
+ private extension Lambda {
102
+ /// the default json encoder used in `EventLoopLambdaHandler` if Out == Encodable
103
+ static let defaultJSONEncoder = JSONEncoder ( )
104
+
105
+ /// the default json decoder used in `EventLoopLambdaHandler` if In == Decodable
106
+ static let defaultJSONDecoder = JSONDecoder ( )
107
+ }
108
+
103
109
public extension EventLoopLambdaHandler where In: Decodable , Out == Void {
104
110
func encode( allocator: ByteBufferAllocator , value: Void ) throws -> ByteBuffer ? {
105
111
nil
106
112
}
107
113
108
114
func decode( buffer: ByteBuffer ) throws -> In {
109
- // FIXME: reusable JSONDecoder
110
- try JSONDecoder ( ) . decode ( In . self, from: buffer)
115
+ try Lambda . defaultJSONDecoder. decode ( In . self, from: buffer)
111
116
}
112
117
}
0 commit comments