从Netty 4.0 CR3转换为4.0.10-final

时间:2013-10-14 17:55:29

标签: java netty

我正在将我的框架Netty版本升级到最新版本,似乎API已经崩溃(我知道在最终版本发布之前我不应该使用它);我一直在阅读文档,并通过课程来尝试找到一个可行的解决方案,但我找不到一个。

    ctx.nextInboundMessageBuffer().add(message);
    ctx.fireInboundBufferUpdated();

    if (additionalBuf != null) {
        ChannelHandlerContext head = ctx.pipeline().firstContext();
        head.nextInboundByteBuffer().writeBytes(additionalBuf);
        head.fireInboundBufferUpdated();
    }

我正在尝试转换为新API,感谢任何帮助。

完整代码:

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (!in.isReadable()) {
        return;
    }

    int messageId = in.readUnsignedByte();

    ByteBuf additionalBuf = null;
    if (in.isReadable()) {
        additionalBuf = in.readBytes(in.readableBytes());
    }

    ChannelPipeline pipeline = ctx.pipeline();
    pipeline.remove(HandshakeDecoder.class);

    HandshakeMessage message = HandshakeMessage.forId(messageId);

    switch (message) {
    case LOGIN_MESSAGE:
        break;
    case UPDATE_MESSAGE:
        break;
    default:
        throw new IllegalStateException("Unexpected message id: " + messageId);
    }

    ctx.nextInboundMessageBuffer().add(message);
    ctx.fireInboundBufferUpdated();

    if (additionalBuf != null) {
        ChannelHandlerContext head = ctx.pipeline().firstContext();
        head.nextInboundByteBuffer().writeBytes(additionalBuf);
        head.fireInboundBufferUpdated();
    }
}

1 个答案:

答案 0 :(得分:0)

我认为这里有解释:

http://netty.io/news/2013/06/18/4-0-0-CR5.html

一般情况下,您只需使用fireChannelRead(...)