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


-----Original Message-----
From: Emmanuel Lecharny [mailto:[email protected]] On Behalf Of Emmanuel 
Lecharny
Sent: Monday, June 22, 2009 9:56 AM
To: [email protected]
Subject: Re: Handling variable length request/response in MINA

David Rosenstrauch wrote:
>>>
>>> DR
>
> Hmmm ... yeah, that's a problem.  I'll have to fix this.
>
> Thanks for the heads up.

Just keep me informed if this is not anymore a problem...

May be we should document this kind of decoding on the web site too... 
It can e helpfull !
>
> DR
>


-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to