mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andres Quijano" <tulsi...@gmail.com>
Subject ByteBuffer remaining and hasRemaining
Date Wed, 14 Jun 2006 19:00:58 GMT
Hi

I'm new to MINA. I've been going through the examples and I'm not
quite understanding how the NEED_DATA and returning null in the
decoders work. Specifically, I do not understand the remaining and
hasRemaining method in ByteBuffer.

The example decoder goes like this:

if (in.remaining() < Constants.HEADER_LEN) {
   return MessageDecoderResult.NEED_DATA;
}

I interpret it like "if there are less remaining bytes than the size
of the header, we need more data", which doesn't make sense.

Also, I tried to do something like this in a decoder:

if (in.hasRemaining()) {
   return null; // Need more data.
}

On the beggining of the method. The method get's called three times,
and it never returns false on the hasRemaining method.

The question goes simply to: how to know if there's enough data when
decoding an object with many primitives and some strings (of variable
size)?

Thanks

Mime
View raw message