我正在将我的框架 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();
    }
}