/* Function   : decodeVersionAndState
 * Arguments  : stream - socket, through which the data is received 
 * Description: receives remote replication daemon version and state from the
 *				given socket
 */
Version*
ReplicatorStateMachine::decodeVersionAndState( Stream* stream )
{
	Version* newVersion = new Version;
	// decode remote replication daemon version
   	if( ! newVersion->decode( stream ) ) {
    	dprintf( D_ALWAYS, "ReplicatorStateMachine::decodeVersionAndState "
                           "cannot read remote daemon version\n" );
       	delete newVersion;
       
       	return 0;
   	}
   	int remoteReplicatorState;

   	stream->decode( );
	// decode remore replication daemon state
   	if( ! stream->code( remoteReplicatorState ) ) {
    	dprintf( D_ALWAYS, "ReplicatorStateMachine::decodeVersionAndState "
                           "unable to decode the state\n" );
       	delete newVersion;
       
       	return 0;
   	}
   	newVersion->setState( ReplicatorState( remoteReplicatorState ) );

   	return newVersion;
   	//updateVersionsList( *newVersion );
}