<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() &lt; 4) {</div><div>            return null;</div><div>        }</div><div><br></div><div>        int dataLen = buffer.getInt(buffer.readerIndex());</div><div>        if (dataLen &lt;= 0) {</div>

<div>            throw new StreamCorruptedException(&quot;invalid data length: &quot; + dataLen);</div><div>        }</div><div><br></div><div>        if (buffer.readableBytes() &lt; 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&#39;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>