<div dir="ltr">Hi,<div><br></div><div> I have a problem and am trying to find the best solution for. In netty, I am using a FrameDecoder that simply does the following:</div><div><br></div><div><div><div> protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {</div>
<div><br></div><div> if (buffer.readableBytes() < 4) {</div><div> return null;</div><div> }</div><div><br></div><div> int dataLen = buffer.getInt(buffer.readerIndex());</div><div> if (dataLen <= 0) {</div>
<div> throw new StreamCorruptedException("invalid data length: " + dataLen);</div><div> }</div><div><br></div><div> if (buffer.readableBytes() < dataLen + 4) {</div><div> return null;</div>
<div> }</div><div><br></div><div> buffer.skipBytes(4);</div><div><br></div><div> return buffer;</div><div> }</div><div><br></div></div><div>On the next handler, I use the buffer to extract the request from (and other information). The problem I have is that something might fail and I won't read the whole buffer. In this case, things gets corrupted for requests that follow. Once I do read the whole buffer, things works correctly. I can skipBytes in the size of (writerIndex - readerIndex) in case of an exception, but then I wonder how does the built in ObjectDecoder handles this case..., maybe I am missing something?</div>
<div><br></div><div>cheers,</div><div>shay.banon</div></div></div>