smf/smfcredentialmgr/smfcredmgrcommon/src/smfutils.cpp
changeset 14 a469c0e6e7fb
child 18 013a02bf2bb0
equal deleted inserted replaced
13:b5d63d5fc252 14:a469c0e6e7fb
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "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  * Lasse Laasonen, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Description:
       
    13  * This header contains utility routines used by server and client
       
    14  */
       
    15 
       
    16 #include <s32strm.h>
       
    17 #include "smfutils.h"
       
    18 
       
    19 namespace SmfUtils
       
    20 	{
       
    21 	void ExternalizeDesL(const TDesC8& aDes, RWriteStream& aStream)
       
    22 		{
       
    23 		TInt length = aDes.Length();
       
    24 		aStream.WriteInt32L(length);
       
    25 
       
    26 		if (length > 0)
       
    27 			{
       
    28 			aStream << aDes;
       
    29 			}
       
    30 		}
       
    31 
       
    32 	TInt InternalizeDesL(RBuf8& aDes, RReadStream& aStream)
       
    33 		{
       
    34 		TInt length = aStream.ReadInt32L();
       
    35 		aDes.Close();
       
    36 
       
    37 		if (length > 0)
       
    38 			{
       
    39 			aDes.CreateL(aStream, length);
       
    40 			}
       
    41 		else
       
    42 			{
       
    43 			aDes.CreateL(KNullDesC8);
       
    44 			}
       
    45 
       
    46 		return length;
       
    47 		}
       
    48 
       
    49 	void ExternalizeDesL(const TDesC16& aDes, RWriteStream& aStream)
       
    50 		{
       
    51 		TInt length = aDes.Length();
       
    52 		aStream.WriteInt32L(length);
       
    53 
       
    54 		if (length > 0)
       
    55 			{
       
    56 			aStream << aDes;
       
    57 			}
       
    58 		}
       
    59 
       
    60 	HBufC16* InternalizeDesL(RReadStream& aStream)
       
    61 		{
       
    62 		TInt length = aStream.ReadInt32L();
       
    63 		if (length)
       
    64 			{
       
    65 			HBufC* buf = HBufC::NewL(aStream, length);
       
    66 			return buf;
       
    67 			}
       
    68 		else
       
    69 			return NULL;
       
    70 		}
       
    71 	TInt InternalizeDesL( RBuf16& aDes, RReadStream& aStream )
       
    72 	    {
       
    73 	    TInt length = aStream.ReadInt32L();
       
    74 	    
       
    75 	    aDes.Close();
       
    76 	    
       
    77 	    if( length > 0 )
       
    78 	        {
       
    79 	        aDes.CreateL( aStream, length );
       
    80 	        }
       
    81 	    else
       
    82 	        {
       
    83 	        aDes.CreateL( KNullDesC16 );
       
    84 	        }
       
    85 
       
    86 	    return length;
       
    87 	    }
       
    88 	void ExternalizeInt64L(const TInt64& aInt, RWriteStream& aStream)
       
    89 		{
       
    90 		TInt32 low = I64LOW( aInt );
       
    91 		TInt32 high = I64HIGH( aInt );
       
    92 		aStream.WriteInt32L(low);
       
    93 		aStream.WriteInt32L(high);
       
    94 		}
       
    95 
       
    96 	void InternalizeInt64L(TInt64& aInt, RReadStream& aStream)
       
    97 		{
       
    98 		TInt32 low = aStream.ReadInt32L();
       
    99 		TInt32 high = aStream.ReadInt32L();
       
   100 		aInt = MAKE_TINT64(high, low);
       
   101 		}
       
   102 
       
   103 	}