multimediacommsengine/mmceshared/src/mceserial.cpp
branchrcs
changeset 49 64c62431ac08
parent 0 1bce908db942
equal deleted inserted replaced
44:fb024d5e35fa 49:64c62431ac08
    59 
    59 
    60 // -----------------------------------------------------------------------------
    60 // -----------------------------------------------------------------------------
    61 // MceSerial::EncodeL
    61 // MceSerial::EncodeL
    62 // -----------------------------------------------------------------------------
    62 // -----------------------------------------------------------------------------
    63 //
    63 //
       
    64 void MceSerial::EncodeL( const TDesC16& aString, RWriteStream& aWriteStream )
       
    65     {
       
    66     aWriteStream.WriteUint32L( aString.Length() );
       
    67     if ( aString.Length() > 0 )
       
    68         {
       
    69         aWriteStream.WriteL( aString );
       
    70         }
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // MceSerial::EncodeL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
    64 void MceSerial::EncodeL( HBufC8* aString, RWriteStream& aWriteStream )
    77 void MceSerial::EncodeL( HBufC8* aString, RWriteStream& aWriteStream )
    65     {
    78     {
    66     if ( aString )
    79     if ( aString )
    67         {
    80         {
    68         EncodeL( *aString, aWriteStream );
    81         EncodeL( *aString, aWriteStream );
    70     else
    83     else
    71         {
    84         {
    72         EncodeL( KNullDesC8, aWriteStream );
    85         EncodeL( KNullDesC8, aWriteStream );
    73         }
    86         }
    74     }
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // MceSerial::EncodeL
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void MceSerial::EncodeL( HBufC16* aString, RWriteStream& aWriteStream )
       
    94     {
       
    95     if ( aString )
       
    96         {
       
    97         EncodeL( *aString, aWriteStream );
       
    98         }
       
    99     else
       
   100         {
       
   101         EncodeL( KNullDesC, aWriteStream );
       
   102         }
       
   103     }
       
   104 
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // MceSerial::DecodeL
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void MceSerial::DecodeL( HBufC16*& aBuffer, RReadStream& aReadStream )
       
   111     {
       
   112    delete aBuffer;
       
   113    aBuffer = NULL;
       
   114        
       
   115    TUint32 len = aReadStream.ReadUint32L();
       
   116    
       
   117     if ( len > 0 )
       
   118         {
       
   119         HBufC16* tmpBuffer = HBufC16::NewLC ( len );
       
   120         TPtr16 bufPtr = tmpBuffer->Des();
       
   121         aReadStream.ReadL( bufPtr, len );
       
   122         CleanupStack::Pop( tmpBuffer );
       
   123         aBuffer = tmpBuffer;
       
   124         }
       
   125     else
       
   126         {
       
   127         aBuffer = KNullDesC().AllocL();
       
   128         }           
       
   129     }
       
   130 
    75 
   131 
    76 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
    77 // MceSerial::DecodeL
   133 // MceSerial::DecodeL
    78 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
    79 //
   135 //
   102 // MceSerial::DecodeL
   158 // MceSerial::DecodeL
   103 // -----------------------------------------------------------------------------
   159 // -----------------------------------------------------------------------------
   104 //
   160 //
   105 void MceSerial::DecodeL( CDesC8Array*& aArray, RReadStream& aReadStream )
   161 void MceSerial::DecodeL( CDesC8Array*& aArray, RReadStream& aReadStream )
   106     {
   162     {
   107     delete aArray;
   163     if (aArray!=NULL )
   108     aArray = NULL;
   164         {
   109     
   165         aArray->Reset();
       
   166         delete aArray;
       
   167         aArray = NULL;
       
   168         }
       
   169         
   110     TInt count = aReadStream.ReadUint32L();
   170     TInt count = aReadStream.ReadUint32L();
   111 	CDesC8ArrayFlat* tmpArray = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
   171 	CDesC8ArrayFlat* tmpArray = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
   112 	CleanupStack::PushL( tmpArray );
   172 	CleanupStack::PushL( tmpArray );
   113 	for ( int i=0;i<count;i++ )
   173 	for ( int i=0;i<count;i++ )
   114 	    {
   174 	    {
   171     aWriteStream.WriteUint32L( count );
   231     aWriteStream.WriteUint32L( count );
   172     for (int i=0; i<count; i++)
   232     for (int i=0; i<count; i++)
   173     	{
   233     	{
   174     	aWriteStream.WriteInt32L(aArray[i]);
   234     	aWriteStream.WriteInt32L(aArray[i]);
   175     	}
   235     	}
       
   236     }
       
   237 
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // MceSerial::EncodeL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void MceSerial::EncodeL( RPointerArray<TUriC8>& aArray,
       
   244                          RWriteStream& aWriteStream )
       
   245     {
       
   246     TInt count = aArray.Count();
       
   247     aWriteStream.WriteUint32L( count );
       
   248     for (int i=0; i<count; i++)
       
   249         {
       
   250         TInt length = aArray[i]->UriDes().Length();
       
   251         aWriteStream.WriteUint32L(length);
       
   252         aWriteStream.WriteL(aArray[i]->UriDes());
       
   253         }
       
   254     }
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // MceSerial::EncodeL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void MceSerial::EncodeL(TInetAddr& aAddr, RWriteStream& aWriteStream)
       
   262     {
       
   263     TBuf16<60> buf16; 
       
   264     aAddr.Output(buf16);
       
   265     TBuf8<60> buf8;
       
   266     buf8.Copy(buf16);
       
   267     MceSerial::EncodeL(buf8, aWriteStream);
       
   268     }
       
   269 
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // MceSerial::DecodeL
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void MceSerial::DecodeL(TInetAddr& aAddr, RReadStream& aReadStream)
       
   276     {
       
   277     TBuf8<100>  buf8; 
       
   278     MceSerial::DecodeL(buf8, aReadStream);
       
   279     TBuf16<100> buf16;
       
   280     buf16.Copy(buf8);
       
   281     aAddr.Input(buf16);
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // MceSerial::DecodeL
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void MceSerial::DecodeL( RPointerArray<TUriC8>& aArray,
       
   289         RReadStream& aReadStream )
       
   290     {
       
   291     aArray.ResetAndDestroy();
       
   292     TInt count = aReadStream.ReadUint32L();
       
   293     for (int i=0; i<count; i++)
       
   294         {
       
   295         TInt length = aReadStream.ReadUint32L();
       
   296 #if 0      
       
   297         iPath.Zero();
       
   298         aReadStream.ReadL(iPath, length);
       
   299         
       
   300         TUriParser8* parser = new (ELeave) TUriParser8;        
       
   301         User::LeaveIfError(parser->Parse(iPath) );
       
   302         aArray.AppendL( parser);
       
   303 #endif  
       
   304         HBufC8* item = HBufC8::NewLC( length );
       
   305         TPtr8 ptr(item->Des());
       
   306         aReadStream.ReadL( ptr , length );        
       
   307 
       
   308         TUriParser8* parser = new (ELeave) TUriParser8;        
       
   309         User::LeaveIfError(parser->Parse(ptr) );
       
   310         CleanupStack::Pop(item);        
       
   311         CleanupStack::PushL(parser);
       
   312         aArray.AppendL( parser);
       
   313         CleanupStack::Pop(parser);
       
   314 
       
   315         }
   176     }
   316     }
   177 
   317 
   178 // -----------------------------------------------------------------------------
   318 // -----------------------------------------------------------------------------
   179 // MceSerial::DecodeL
   319 // MceSerial::DecodeL
   180 // -----------------------------------------------------------------------------
   320 // -----------------------------------------------------------------------------