sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "cafutils.h" sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: HBufC* TCafUtils::ReadDescriptor16L(RReadStream& aStream) sl@0: { sl@0: // Read the unicode data from the stream sl@0: TInt dataLength = aStream.ReadInt32L(); sl@0: HBufC* iData = HBufC::NewL(dataLength); sl@0: CleanupStack::PushL(iData); sl@0: if(dataLength > 0) sl@0: { sl@0: TPtr dataPtr = iData->Des(); sl@0: aStream.ReadL(dataPtr, dataLength); sl@0: } sl@0: CleanupStack::Pop(iData); sl@0: return iData; sl@0: } sl@0: sl@0: void TCafUtils::WriteDescriptor16L(RWriteStream& aStream, const TDesC& aDescriptor) sl@0: { sl@0: // Write unicode data to the stream sl@0: aStream.WriteInt32L(aDescriptor.Length()); sl@0: aStream.WriteL(aDescriptor); sl@0: } sl@0: sl@0: HBufC8* TCafUtils::ReadDescriptor8L(RReadStream& aStream) sl@0: { sl@0: // Read the 8 bit data from a stream sl@0: TInt dataLength = aStream.ReadInt32L(); sl@0: HBufC8* iData = HBufC8::NewL(dataLength); sl@0: CleanupStack::PushL(iData); sl@0: if(dataLength > 0) sl@0: { sl@0: TPtr8 dataPtr = iData->Des(); sl@0: aStream.ReadL(dataPtr, dataLength); sl@0: } sl@0: CleanupStack::Pop(iData); sl@0: return iData; sl@0: } sl@0: sl@0: void TCafUtils::ReadDescriptor8L(RReadStream& aStream, TDes8& aBuffer) sl@0: { sl@0: aBuffer.SetLength(0); sl@0: sl@0: // Read the 8 bit data from a stream sl@0: TInt dataLength = aStream.ReadInt32L(); sl@0: if(dataLength > aBuffer.MaxLength()) sl@0: { sl@0: User::Leave(KErrOverflow); sl@0: } sl@0: if(dataLength > 0) sl@0: { sl@0: aStream.ReadL(aBuffer, dataLength); sl@0: } sl@0: } sl@0: sl@0: void TCafUtils::WriteDescriptor8L(RWriteStream& aStream, const TDesC8& aDescriptor) sl@0: { sl@0: // Write 8 bit data to a stream sl@0: aStream.WriteInt32L(aDescriptor.Length()); sl@0: aStream.WriteL(aDescriptor); sl@0: } sl@0: sl@0: // DLL entry point - only for EKA1 sl@0: