It's in the javadocs: " doDecode() is invoked repeatedly until it returns false "
So there is no need to have a loop in your doDecode implementation for decoding multiple messages. http://mina.apache.org/report/trunk/apidocs/org/apache/mina/filter/codec/CumulativeProtocolDecoder.html#doDecode(org.apache.mina.core.session.IoSession,%20org.apache.mina.core.buffer.IoBuffer,%20org.apache.mina.filter.codec.ProtocolDecoderOutput) Maarten On Mon, Jun 22, 2009 at 7:42 PM, David Rosenstrauch <[email protected]>wrote: > Yongxing Wang wrote: > >> I wrote a simple unit test case where one single buffer contains two >> messages, using the DummySession. After calling decode, it delivers >> me two messages: >> >> IoBuffer in = IoBuffer.wrap(bytesData); <= contains two encoded msgs >> decoder.decode(session, in, session.getDecoderOutput()); assertEquals(2, >> session.getDecoderOutputQueue().size()); >> >> Also, looking at the CumulativeProtocolDecoder(which is one I am >> using), >> >> for (;;) { int oldPos = buf.position(); boolean decoded = >> doDecode(session, buf, out); if (decoded) { if (buf.position() == >> oldPos) { throw new IllegalStateException( "doDecode() can't return >> true when buffer is not consumed."); } >> >> if (!buf.hasRemaining()) { break; } } else { break; } } >> >> doDecode will be called again if there are any remaining bytes in the >> event of successfully decoding one message.... If I am not terribly >> wrong, David, your algorithm is fine. >> >> Thanks, Yong >> > > Awesome - thanks for checking! > > I'll write a test case in our code to verify this. (And to make sure that > it doesn't break in future mina releases.) > > DR >
