if( undecodables == decoders.length )
{
// Throw an exception if all decoders cannot decode data.
in.position( in.limit() ); // Skip data
throw new ProtocolViolationException(
"No appropriate message decoder: " + in.getHexDump() );
}
if( currentDecoder == null )
{
// Decoder is not determined yet (i.e. we need more data)
return false;
}
}
MessageDecoderResult result = currentDecoder.decode( session, in, out );
if( result == MessageDecoder.OK )
{
currentDecoder = null;
return true;
}
else if( result == MessageDecoder.NEED_DATA )
{
return false;
}
else if( result == MessageDecoder.NOT_OK )
{
throw new ProtocolViolationException( "Message decoder returned NOT_OK." );
}
else
{
throw new IllegalStateException( "Unexpected decode result (see your decode()): " + result );
}