Use correct types in default method
Motivation: The default method we added for the MessageToByteEncoder has the incorrect parameter types and so is useless. Modifications: Fix type of parameter. Result: Default method match the protocol requirement.
This commit is contained in:
parent
6d7928beb2
commit
9bb7f6727d
|
@ -104,7 +104,7 @@ public extension MessageToByteEncoder {
|
|||
}
|
||||
}
|
||||
|
||||
public func allocateOutBuffer(ctx: ChannelHandlerContext, data: NIOAny) throws -> ByteBuffer {
|
||||
public func allocateOutBuffer(ctx: ChannelHandlerContext, data: OutboundIn) throws -> ByteBuffer {
|
||||
return ctx.channel!.allocator.buffer(capacity: 256)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,25 @@ public class MessageToByteEncoderTest: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private final class Int32ToByteEncoderWithDefaultImpl : MessageToByteEncoder {
|
||||
typealias OutboundIn = Int32
|
||||
typealias OutboundOut = ByteBuffer
|
||||
|
||||
public func encode(ctx: ChannelHandlerContext, data value: Int32, out: inout ByteBuffer) throws {
|
||||
XCTAssertEqual(MemoryLayout<Int32>.size, 256)
|
||||
out.write(integer: value);
|
||||
}
|
||||
}
|
||||
|
||||
func testEncoderOverrideAllocateOutBuffer() throws {
|
||||
try testEncoder(Int32ToByteEncoder())
|
||||
}
|
||||
|
||||
func testEncoder() throws {
|
||||
try testEncoder(Int32ToByteEncoderWithDefaultImpl())
|
||||
}
|
||||
|
||||
private func testEncoder(_ handler: ChannelHandler) throws {
|
||||
let channel = EmbeddedChannel()
|
||||
|
||||
_ = try channel.pipeline.add(handler: Int32ToByteEncoder()).wait()
|
||||
|
|
Loading…
Reference in New Issue