//-----------------------------------------------------------------------------
// CCFContextSubscriptionImpl::InternalizeL
//-----------------------------------------------------------------------------
//
EXPORT_C void CCFContextSubscriptionImpl::InternalizeL(
    RReadStream& aStream)
{
    FUNC_LOG;

    // Context query
    iContextQuery->InternalizeL( aStream );

    // Indicate only changes flag
    iOnlyChangesIndicated = aStream.ReadInt16L();

    // Enable data object
    iDataObjectEnabled = aStream.ReadInt16L();
}
// -----------------------------------------------------------------------------
// CShapeListManager::InternalizeL()
// Restore the instance from the specified stream
// -----------------------------------------------------------------------------
//
EXPORT_C void CShapeListManager::InternalizeL( RReadStream& aStream )
    {

    TInt count = aStream.ReadInt16L();
    for ( TInt index = 0; index < count; ++index )
        {

        TShape* shape = NULL;
        switch ( TShape::ReadShapeTypeL( aStream ) )
            {
            case KRectangle:
                shape = new ( ELeave ) TRectangle();
                break;

            case KCircle:
                shape = new ( ELeave ) TCircle();
                break;

            default:
                User::Leave( KErrCorrupt );
            }


        CleanupStack::PushL( shape );
        shape->InternalizeL( aStream );
        User::LeaveIfError( iShapeList.Append( shape ) );

        CleanupStack::Pop( shape ); //  Now owned by iShapeList
        }
    }
// ---------------------------------------------------------------------------
// CCmStoreListItem::InternalizeL
// ---------------------------------------------------------------------------
//
EXPORT_C void CCmStoreListItem::InternalizeL( RReadStream& aStream )
    {
    iListId = aStream.ReadUint16L();
    TUint count( aStream.ReadUint16L() );
    iDeviceIds.Reset();
    for( TInt i = 0; i < count; i++ )
        {
        iDeviceIds.Append( aStream.ReadInt16L() );
        }
    count = aStream.ReadUint16L();
    iStatusValues.Reset();
    for( TInt i = 0; i < count; i++ )
        {
        iStatusValues.AppendL( (TCmListItemStatus) aStream.ReadInt16L() );
        }        
    CCmBaseListItem::InternalizeL(aStream);               
    }
// -----------------------------------------------------------------------------
// TSdpTypedTime::InternalizeL
// Internalizes typed time from stream
// -----------------------------------------------------------------------------
//
TSdpTypedTime TSdpTypedTime::InternalizeL(RReadStream& aStream)
    {
    TUint32 high = aStream.ReadUint32L();
    TUint32 low = aStream.ReadUint32L();
    TInt64 value = MAKE_TINT64( high, low );
    TUnit unit = static_cast<TUnit>(aStream.ReadInt16L());
    TSdpTypedTime typedTime(value, unit);
    return typedTime;
    }
/**
Configures the BIC using data contained in a ReadStream
 
@param aReadStream 	A read stream containing BIC data
*/
void CCmdCustomCommand::InternalizeL(RReadStream& aReadStream)
	{
	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
	iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L());

	iInfo = new (ELeave) CSsmCustomCommandInfo();
	iInfo->InternalizeL(aReadStream);
#ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
	iPriority = aReadStream.ReadUint16L();
#endif	
	}
void CTestContextData::InternalizeL( RReadStream& aStream )
    {
    TInt len = 0;
    
    len = aStream.ReadInt16L();
    HBufC* buf = HBufC::NewLC( len );
    TPtr bufPtr( buf->Des() );
    aStream.ReadL( bufPtr, len );
    delete iKey;
    iKey = buf;
    CleanupStack::Pop( buf );
    buf = NULL;
    
    len = aStream.ReadInt16L();
    buf = HBufC::NewLC( len );
    bufPtr.Set( buf->Des() );
    aStream.ReadL( bufPtr, len );
    delete iValue;
    iValue = buf;
    CleanupStack::Pop( buf );
    }
/**
Configures the BIC using data contained in a ReadStream
 
@param aReadStream 	A read stream containing BIC data
*/
void CCmdPublishSwp::InternalizeL(RReadStream& aReadStream)
	{
	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
	iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L());
	const TUint key = aReadStream.ReadUint32L();
	const TInt value = aReadStream.ReadInt32L();	
#ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
	iPriority = aReadStream.ReadUint16L();
#endif
	TSsmSwp swpInfo(key, value);
	iSwpInfo = swpInfo;
	}
//-----------------------------------------------------------------------------
// CCFActionIndicationImpl::InternalizeL
//-----------------------------------------------------------------------------
//
EXPORT_C void CCFActionIndicationImpl::InternalizeL( RReadStream& aStream )
    {
    FUNC_LOG;
    
    // Clean up just in case
    delete iIdentifier;
    iIdentifier = NULL;
    iParameters.ResetAndDestroy();
    
    TInt len = 0;

    // Identifier
    len = aStream.ReadInt16L();
    iIdentifier = ReadBufferFromStreamLC( len, aStream );
    CleanupStack::Pop( iIdentifier );
    
    // Parameters
    HBufC* key = NULL;
    HBufC* value = NULL;
    TInt count = aStream.ReadInt16L();
    for( TInt i = 0; i < count; i++ )
        {
        // Key length and data
        len = aStream.ReadInt16L();
        key = ReadBufferFromStreamLC( len, aStream );
        
        // Value length and data
        len = aStream.ReadInt16L();
        value = ReadBufferFromStreamLC( len, aStream );
        
        // Append
        CCFKeyValuePair* keyValuePair = CCFKeyValuePair::NewL( key, value );
        CleanupStack::Pop( value );
        CleanupStack::Pop( key );

        CleanupStack::PushL( keyValuePair );
        iParameters.AppendL( keyValuePair );
        CleanupStack::Pop( keyValuePair );
        }
    }
void TTcSettings::doLoadL( RReadStream& aStream )
	{
	// Check that the file is of correct version
	TInt version = aStream.ReadInt16L();
	if( version == KTcSettingsVersion )
		{
		// Read bearer selection
		iBearerType = aStream.ReadInt32L() ;
		// Read autoconnect selection
		iAutoConnect = aStream.ReadInt16L();
		// Read TCP port selection
		iTCPPort = aStream.ReadInt16L();
		// Read IAP Id
		iIAPId = aStream.ReadInt16L();
		// Read CSY name
		iCSYName = aStream.ReadInt32L();
		// Read comms port name
		iCommPort = aStream.ReadInt32L();
		// Read baudrate of comms
		iBaudrate = aStream.ReadInt32L();
		// Read first run flag
		iIsFirstRun = aStream.ReadInt16L();
		
		// Read remote TCP address as string
		
		// Read length first
		TUint16 length = aStream.ReadInt16L();

		TBuf<40> buf;
		aStream.ReadL( buf, length);
		iTCPRemoteAddr.Input(buf);
			
		}
	}
//-----------------------------------------------------------------------------
// CCFActionSubscriptionImpl::InternalizeL
//-----------------------------------------------------------------------------
//
EXPORT_C void CCFActionSubscriptionImpl::InternalizeL( RReadStream& aStream )
    {
    FUNC_LOG;
    
    delete iIdentifier;
    iIdentifier = NULL;
    
    TInt length = aStream.ReadInt16L();
    if( length > 0 )
        {
        iIdentifier = HBufC::NewL( length );
        TPtr identifierPtr = iIdentifier->Des();
        aStream.ReadL( identifierPtr, length );
        }
    }
void CNcdNodePreview::InternalizeL( RReadStream& aStream )
    {
    DLTRACEIN((""));

    // Read the class id first because it is set to the stream in internalize
    // function and it is not read from the stream anywhere else.
    TInt classId( aStream.ReadInt32L() );
    if ( classId != ClassId() )
        {
        DLERROR(("Wrong class id"));
        DASSERT( EFalse );
        // Leave because the stream does not match this class object
        User::Leave( KErrCorrupt );
        }
    
    iFileCount = aStream.ReadInt16L();

    HBufC* previewMimeType = 0;
    iPreviewMimeTypes.ResetAndDestroy();
    for( int i = 0; i < iFileCount; i++ )
        {
        InternalizeDesL( previewMimeType, aStream );
        CleanupStack::PushL( previewMimeType );
        iPreviewMimeTypes.AppendL( previewMimeType );
        CleanupStack::Pop( previewMimeType );
        }
        
    HBufC* uri = 0;
    iUris.ResetAndDestroy();
    for( int i = 0; i < iFileCount; i++ )
        {
        InternalizeDesL( uri, aStream );
        CleanupStack::PushL( uri );
        iUris.AppendL( uri );
        CleanupStack::Pop( uri );
        }
    
    // Try to update MIME from downloaded previews
    UpdateMimesFromPreviewManagerL();
    DLTRACEOUT((""));
    }
// ---------------------------------------------------------------------------
// CCmFillRule::InternalizeL
// ---------------------------------------------------------------------------
//
void CCmFillRule::InternalizeL( RReadStream& aStream )
    {
    // Content
    delete iName;
    iName = NULL;

    TInt bufLength = aStream.ReadInt32L();    
    iName = HBufC8::NewL( aStream, bufLength );
    
    // cleanup
    iRuleArray.ResetAndDestroy();
    
    iAmount = aStream.ReadInt32L();
    iRealSize = aStream.ReadInt32L();
    iRealCount = aStream.ReadInt32L();
    iLimitType = (TCmLimitType)aStream.ReadInt16L();
    iMethod = (TCmFillMethod)aStream.ReadInt16L();
    iMediaType = (TCmMediaType)aStream.ReadInt16L();
    iSelected = (TCmFillRuleStatus)aStream.ReadInt16L();
    iStatus = (TCmListItemStatus)aStream.ReadInt16L();
    iPriority = (TUint8)aStream.ReadInt8L();
    iTemplateId = (TUint8)aStream.ReadInt8L();
    iId = (TUint)aStream.ReadInt32L();
    
    // rule count 
    TInt ruleCount = aStream.ReadInt16L();
    
    // Then internalize them from the stream one by one
    for (TInt index = 0; index < ruleCount; index++ )
        {
        CCmRule* newRule = CCmRule::NewLC();
        newRule->InternalizeL( aStream );   
        iRuleArray.AppendL( newRule );
        CleanupStack::Pop( newRule ); 
        newRule = NULL;
        }
        
    // cleanup
    iMediaServerArray.ResetAndDestroy();
    
    // media Server count
    TInt mediaServerCount = aStream.ReadInt16L();
    
    // Then internalize them from the stream one by one
    for (TInt index = 0; index < mediaServerCount; index++ )
        {
        CCmMediaServer* newServer = CCmMediaServer::NewLC();
        newServer->InternalizeL( aStream );     
        iMediaServerArray.AppendL( newServer );
        CleanupStack::Pop( newServer ); 
        newServer = NULL;
        }
        
    TInt excAlbumsCount( aStream.ReadInt16L() );
    bufLength = KErrNone;
    HBufC* temp = NULL;
    for ( TInt index(0); index < excAlbumsCount ; index++ )
        {
        bufLength = aStream.ReadInt32L();
        temp = HBufC::NewLC( aStream, bufLength );
        iExcAlbums->AppendL( *temp );
        CleanupStack::PopAndDestroy( temp );
        temp = NULL;
        }         

    TInt excPlayListCount( aStream.ReadInt16L() );
    bufLength = KErrNone;
    for ( TInt index(0); index < excPlayListCount ; index++ )
        {
        bufLength = aStream.ReadInt32L();
        temp = HBufC::NewLC( aStream, bufLength );
        iExcPlayLists->AppendL( *temp );
        CleanupStack::PopAndDestroy( temp );
        temp = NULL;
        }                         
    }
/**
Configures the BIC using data contained in a ReadStream
 
@param aReadStream 	A read stream containing BIC data
*/
void CCmdPersistHalAttributes::InternalizeL(RReadStream& aReadStream)
	{
	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
	}