3

I'm working on the Apache PLC4X project where we implement industry PLC protocols using Netty. We are currently encountering a problem with decoding responses as soon as the size of these exceed a limit of 512 bytes.

As soon as the size of the response exceeds these 512 bytes, the decode method of our MessageToMessageCodec based protocol layer implementation only receives a 512 byte large ByteBuf. Directly after this, the method is called again with the rest of the packet.

How would be the correct way to handle this?

Justin Mclean
  • 1,615
  • 13
  • 14
Christofer Dutz
  • 2,305
  • 1
  • 23
  • 34

1 Answers1

3

You should use the ByteToMessageDecoder here which will allow you to buffer data. See the javadocs for more details on how you can archive this. But basically its something like:

YourDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        if (in.readableBytes() < 1024) {
            return;
        }
        ....
    }
}
Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • 2
    Thank you so much for this info ... you definitely made my day! Worked like a charm and adjusting the lowest protocol layer was super easy. – Christofer Dutz Nov 29 '18 at 09:12