我正在将我的框架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();
}
}
答案 0 :(得分:0)