收到ByteBuf解码成一个字节数组。一个典型的TCP / IP设置将是:
ChannelPipeline pipeline = ...;
/ / 解码
/ / Decoders
pipeline.addLast("frameDecoder",
new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
pipeline.addLast("bytesDecoder",
new ByteArrayDecoder());
/ / 编码
// Encoder
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("bytesEncoder", new ByteArrayEncoder());
/ / 然后您可以使用字节数组而不是ByteBuf作为一个信息:
void channelRead(ChannelHandlerContext ctx, byte[] bytes) {
...
}
本文详细介绍了如何在TCP/IP环境中将ByteBuf解码为字节数组,并通过示例展示了如何在ChannelPipeline中实现解码与编码过程。主要内容包括配置解码器与编码器,以及如何在接收字节数组时进行处理。
1891

被折叠的 条评论
为什么被折叠?



