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:
Norman Maurer 2017-11-08 01:14:43 -08:00
parent 6d7928beb2
commit 9bb7f6727d
2 changed files with 19 additions and 1 deletions

View File

@ -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) return ctx.channel!.allocator.buffer(capacity: 256)
} }
} }

View File

@ -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 { func testEncoder() throws {
try testEncoder(Int32ToByteEncoderWithDefaultImpl())
}
private func testEncoder(_ handler: ChannelHandler) throws {
let channel = EmbeddedChannel() let channel = EmbeddedChannel()
_ = try channel.pipeline.add(handler: Int32ToByteEncoder()).wait() _ = try channel.pipeline.add(handler: Int32ToByteEncoder()).wait()