ximpfw/core/srcutils/ximpobjecthelpers.cpp
changeset 51 61fad867f68e
equal deleted inserted replaced
-1:000000000000 51:61fad867f68e
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Helpers for handling objects
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ximpobjecthelpers.h"
       
    19 
       
    20 // ==================== TXIMPHBuf8Packer MEMBER FUNCTIONS ====================
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // TXIMPHBuf8Packer::PackArrayL()
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 EXPORT_C HBufC8* TXIMPHBuf8Packer::PackArrayL( const RPointerArray< HBufC8 >& aBufferArray )
       
    27     {
       
    28     CBufFlat* packBuf = CBufFlat::NewL( KObjectBufGranurality );
       
    29     CleanupStack::PushL( packBuf );
       
    30 
       
    31     RBufWriteStream ws;
       
    32     ws.Open( *packBuf ); // CSI: 65 #
       
    33     CleanupClosePushL( ws );
       
    34 
       
    35     // Get count of objects
       
    36     TInt objCount( aBufferArray.Count() );
       
    37     // write the count
       
    38     ws.WriteInt32L( objCount );
       
    39     // objects
       
    40     for ( TInt count(0); count < objCount; count++ )
       
    41         {
       
    42         ws.WriteInt32L( aBufferArray[ count ]->Size() );
       
    43         ws.WriteL( *aBufferArray[ count ] );
       
    44         }
       
    45 
       
    46     ws.CommitL();
       
    47     CleanupStack::PopAndDestroy(); //ws
       
    48 
       
    49     HBufC8* packBufDesc = packBuf->Ptr(0).AllocL();
       
    50     CleanupStack::PopAndDestroy( packBuf );
       
    51 
       
    52     return packBufDesc;
       
    53     }
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // TXIMPHBuf8Packer::UnPackArrayL()
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C void TXIMPHBuf8Packer::UnPackArrayL( RPointerArray< HBufC8 >& aBufferArray, const TDesC8& aPack  )
       
    61     {
       
    62 	CleanupClosePushL( aBufferArray );
       
    63 	// No reset
       
    64     if ( ! aPack.Length() )
       
    65         {
       
    66         // empty, don't attempt to unpack
       
    67         return;
       
    68         }
       
    69 
       
    70     RDesReadStream rs;
       
    71     CleanupClosePushL( rs );
       
    72     rs.Open( aPack ); // CSI: 65 #
       
    73 
       
    74     // read the object count
       
    75     TInt objCount( rs.ReadInt32L() );
       
    76 
       
    77 	for ( TInt count = 0; count < objCount; count++ )
       
    78         {
       
    79         TInt length = rs.ReadInt32L();
       
    80         HBufC8* theObject = HBufC8::NewLC( length );
       
    81         TPtr8 theObjectPtr = theObject->Des();
       
    82         
       
    83         rs.ReadL( theObjectPtr, length );
       
    84         aBufferArray.AppendL( theObject );
       
    85 		}
       
    86     CleanupStack::Pop( objCount ); // all the objects
       
    87     CleanupStack::PopAndDestroy(); // rs   
       
    88     CleanupStack::Pop( &aBufferArray );
       
    89     }
       
    90 // End of file