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