|
1 /* |
|
2 * Copyright (c) 2003-2009 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <s32strm.h> |
|
22 #include "cafutils.h" |
|
23 |
|
24 using namespace ContentAccess; |
|
25 |
|
26 HBufC* TCafUtils::ReadDescriptor16L(RReadStream& aStream) |
|
27 { |
|
28 // Read the unicode data from the stream |
|
29 TInt dataLength = aStream.ReadInt32L(); |
|
30 HBufC* iData = HBufC::NewL(dataLength); |
|
31 CleanupStack::PushL(iData); |
|
32 if(dataLength > 0) |
|
33 { |
|
34 TPtr dataPtr = iData->Des(); |
|
35 aStream.ReadL(dataPtr, dataLength); |
|
36 } |
|
37 CleanupStack::Pop(iData); |
|
38 return iData; |
|
39 } |
|
40 |
|
41 void TCafUtils::WriteDescriptor16L(RWriteStream& aStream, const TDesC& aDescriptor) |
|
42 { |
|
43 // Write unicode data to the stream |
|
44 aStream.WriteInt32L(aDescriptor.Length()); |
|
45 aStream.WriteL(aDescriptor); |
|
46 } |
|
47 |
|
48 HBufC8* TCafUtils::ReadDescriptor8L(RReadStream& aStream) |
|
49 { |
|
50 // Read the 8 bit data from a stream |
|
51 TInt dataLength = aStream.ReadInt32L(); |
|
52 HBufC8* iData = HBufC8::NewL(dataLength); |
|
53 CleanupStack::PushL(iData); |
|
54 if(dataLength > 0) |
|
55 { |
|
56 TPtr8 dataPtr = iData->Des(); |
|
57 aStream.ReadL(dataPtr, dataLength); |
|
58 } |
|
59 CleanupStack::Pop(iData); |
|
60 return iData; |
|
61 } |
|
62 |
|
63 void TCafUtils::ReadDescriptor8L(RReadStream& aStream, TDes8& aBuffer) |
|
64 { |
|
65 aBuffer.SetLength(0); |
|
66 |
|
67 // Read the 8 bit data from a stream |
|
68 TInt dataLength = aStream.ReadInt32L(); |
|
69 if(dataLength > aBuffer.MaxLength()) |
|
70 { |
|
71 User::Leave(KErrOverflow); |
|
72 } |
|
73 if(dataLength > 0) |
|
74 { |
|
75 aStream.ReadL(aBuffer, dataLength); |
|
76 } |
|
77 } |
|
78 |
|
79 void TCafUtils::WriteDescriptor8L(RWriteStream& aStream, const TDesC8& aDescriptor) |
|
80 { |
|
81 // Write 8 bit data to a stream |
|
82 aStream.WriteInt32L(aDescriptor.Length()); |
|
83 aStream.WriteL(aDescriptor); |
|
84 } |
|
85 |
|
86 // DLL entry point - only for EKA1 |