|
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 // No reset |
|
63 if ( ! aPack.Length() ) |
|
64 { |
|
65 // empty, don't attempt to unpack |
|
66 return; |
|
67 } |
|
68 |
|
69 RDesReadStream rs; |
|
70 CleanupClosePushL( rs ); |
|
71 rs.Open( aPack ); // CSI: 65 # |
|
72 |
|
73 // read the object count |
|
74 TInt objCount( rs.ReadInt32L() ); |
|
75 |
|
76 for ( TInt count = 0; count < objCount; count++ ) |
|
77 { |
|
78 TInt length = rs.ReadInt32L(); |
|
79 HBufC8* theObject = HBufC8::NewLC( length ); |
|
80 TPtr8 theObjectPtr = theObject->Des(); |
|
81 |
|
82 rs.ReadL( theObjectPtr, length ); |
|
83 aBufferArray.AppendL( theObject ); |
|
84 } |
|
85 CleanupStack::Pop( objCount ); // all the objects |
|
86 CleanupStack::PopAndDestroy(); // rs |
|
87 } |
|
88 // End of file |