Le 7/26/12 7:10 PM, ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) a écrit :
Hi Emmanuel,
Quick question...Does the IoBuffer.position() return a non-zero value when
data is being resent because of an earlier NEED_DATA result ? As per the
description of position, the position is the index of next element to be
read or written.
for (int i = decoders.length - 1; i >= 0; i--) {
MessageDecoder decoder = decoders[i];
int limit = in.limit();
int pos = in.position();
MessageDecoderResult result;
try {
result = decoder.decodable(session, in);
} finally {
in.position(pos);
in.limit(limit);
}
As you can see, whatever the decoding result is, the position is reset
to its initial value.
This is necessary because we just check that we can decode the message,
and as we will decode it again (yes, don't ask :/)
Then when we know that we can decode a full message, we go through the
'real' decoding, starting from the initial starting point in the buffer.
Now, the position in the buffer is set to the end of the decoded message.
If the message can't be decoded (because we NEED_(more)DATA, the buffer
remain as it was before the doDecode() method was called : the position
and limit are unchanged.
Side note : the way we process the doDecode() method is blatantly
unefiicient :/ When we have successfully decoded a message, we should
*not* redecode it once more. Anyway...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com