简体   繁体   English

Netty 4-编码器未写入后续编码器

[英]Netty 4 - Encoder not writing to following encoder

I currently have set up a networked client that makes use of two encoders, a single decoder, and a ChannelInboundMessageHandlerAdapter<ByteBuf> . 我目前已经建立了一个网络客户端,该客户端使用两个编码器,一个解码器和一个ChannelInboundMessageHandlerAdapter<ByteBuf> The encoders are a MessageToByteEncoder<Packet> and a ByteToByteEncoder . 编码器是MessageToByteEncoder<Packet>ByteToByteEncoder I've tried using a ChannelOutboundMessageHandlerAdapter and a ChannelOutboundByteHandlerAdapter but neither of them remedied the problem. 我试过使用ChannelOutboundMessageHandlerAdapterChannelOutboundByteHandlerAdapter但是它们都不能解决问题。 It enters the first encoder ( PacketEncoder or the MessageToByteEncoder<Packet> ) just fine, but fails to enter the ByteToByteEncoder afterword and no data is sent to the server. 它可以正常输入第一个编码器( PacketEncoderMessageToByteEncoder<Packet> ),但无法输入ByteToByteEncoder后缀,并且没有数据发送到服务器。

My pipeline is set up like so: 我的管道设置如下:

ChannelPipeline pipeline = ch.pipeline();
// Decoders
pipeline.addLast("buffer_length_decoder", new BufferLengthDecoder());
pipeline.addLast("packet_decoder", new PacketDecoder());

// Encoder
pipeline.addLast("buffer_length_encoder", new BufferLengthEncoder());
pipeline.addLast("packet_encoder", new PacketEncoder());

PacketEncoder looks like so: PacketEncoder看起来像这样:

public class PacketEncoder extends MessageToByteEncoder<Packet> {
    private static final Logger logger = LoggerFactory.getLogger(PacketEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) throws Exception {
        ByteBuf buf = msg.buf();
        buf = buf.capacity(buf.readableBytes());
        logger.info(Utils.toHexString(buf.array()));
        out.writeBytes(buf);
    }
}

BufferLengthEncoder looks like so: BufferLengthEncoder看起来像这样:

public class BufferLengthEncoder extends ByteToByteEncoder {
    private static final Logger logger = LoggerFactory.getLogger(BufferLengthEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        logger.info(Utils.toHexString(in.array()));
        out = out.writeInt(in.readableBytes()).writeBytes(in);
    }
}

I have tried changing their order in the pipeline to no avail. 我试图将它们在管道中的顺序更改为无济于事。 I assume that I'm just missing something nonsensical somewhere, but I'm unsure where or what. 我以为我只是在某个地方错过了一些荒谬的东西,但是我不确定在哪里或什么地方。 Any and all help is much appreciated. 任何帮助都将不胜感激。

Thanks in advance! 提前致谢!

Sounds strange to me... could you please write a unit test that shows the problem and open an issue after you are sure it is a bug ? 对我来说听起来很奇怪...您能否编写一个可以显示问题的单元测试,并确定一个错误后再打开一个问题?

https://github.com/netty/netty/issues https://github.com/netty/netty/issues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM