Hi Robert,
I don't believe the use of prefixedDataAvailable for both the type and the
length won't give you the expected result since they will both apply to the
first int in the byte array, which is in your case the type. The reason it
happens only sometimes is likely do to the interaction with what the type is
and the size value in the message, which is of course a problem.
Apparently your message format requires two integers (8 bytes) for the type and
length before you can determine if you have all the data for the message
available for decoding. Consider reading off those two values separately:
if (in.remaining() < 8) {
return false;
}
in.mark();
int type = in.getInt();
int size = in.getInt();
if (in.remaining() < size-8) {
in.reset();
return false;
}
// decode
return true;
Regards,
Jeff Dever.
________________________________________
From: Robert Tomczyk [[email protected]]
Sent: February 6, 2012 7:08 PM
To: [email protected]
Subject: Strange bug in CumulativeProtocolDecoder
Hi. Im using MINA 2.0.4 on windows 7 32-bit. As a decoder im using CPD,
running locally.
On client side decoder works without issues, it takes care of incomplete
message and more than one message in buffer as well. Nothing is blocking.
On server side im using same algorithm.
if(in.prefixedDataAvaliable(4)) // read message type
{
if(in.prefixedDataAvaliable(4)) // read message length
{
if(in.remaining() >= messageLength)
{
// decode
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
Problem is that some of the messages cant pass first step, it doesnt matter
if they are incomplet or overcomplet. They return false. But when i
manually trying to get int, value which should be read is correct. Why is
that happens ? Why it happens only for coupe of messages ?
Encoder sends bytes properly.