|
1 /* |
|
2 * Copyright (c) 2004-2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <RVPbkContactFieldDefaultPriorities.h> |
|
20 #include <VPbkError.h> |
|
21 #include <s32strm.h> |
|
22 #include <s32mem.h> |
|
23 |
|
24 // Priority array static data |
|
25 namespace KPriorityArrayStatic |
|
26 { |
|
27 const TUint8 KArrayVersionNumber = 1; |
|
28 } |
|
29 |
|
30 namespace KPriorityArrayExternalizeSizes |
|
31 { |
|
32 const TInt KVersionNumberSize = 1; |
|
33 const TInt KElementCountSize = 1; |
|
34 const TInt KElementSize = 1; |
|
35 } |
|
36 |
|
37 namespace { |
|
38 |
|
39 TInt DoCalculateBufferSize(const RVPbkContactFieldDefaultPriorities& aPriorities) |
|
40 { |
|
41 TInt bufferSize = KPriorityArrayExternalizeSizes::KVersionNumberSize; |
|
42 bufferSize += KPriorityArrayExternalizeSizes::KElementCountSize; |
|
43 bufferSize += aPriorities.Count() * KPriorityArrayExternalizeSizes::KElementSize; |
|
44 return bufferSize; |
|
45 } |
|
46 |
|
47 void DoFillBuffer(RWriteStream& aWriteStream, |
|
48 const RVPbkContactFieldDefaultPriorities& aPriorities) |
|
49 { |
|
50 // Write version number |
|
51 aWriteStream.WriteUint8L(KPriorityArrayStatic::KArrayVersionNumber); |
|
52 // Write array element count to the stream |
|
53 aWriteStream.WriteUint8L(aPriorities.Count()); |
|
54 |
|
55 // Write each element to the stream |
|
56 for (TInt i = 0; i < aPriorities.Count(); ++i) |
|
57 { |
|
58 aWriteStream.WriteUint8L(aPriorities.At(i)); |
|
59 } |
|
60 } |
|
61 |
|
62 } /// unnamed namespace |
|
63 |
|
64 |
|
65 /** |
|
66 * Default priority array pack format 1: |
|
67 * stream := VersionNumber ElementCount Element* |
|
68 * VersionNumber := TInt8 |
|
69 * ElementCount := TInt8 |
|
70 * Element := TInt8 |
|
71 */ |
|
72 EXPORT_C HBufC8* RVPbkContactFieldDefaultPriorities::ExternalizeLC() const |
|
73 { |
|
74 const TInt bufferSize = DoCalculateBufferSize(*this); |
|
75 HBufC8* buffer = HBufC8::NewLC(bufferSize); |
|
76 TPtr8 bufPtr(buffer->Des()); |
|
77 RDesWriteStream writeStream(bufPtr); |
|
78 writeStream.PushL(); |
|
79 DoFillBuffer(writeStream, *this); |
|
80 writeStream.CommitL(); |
|
81 CleanupStack::PopAndDestroy(&writeStream); |
|
82 return buffer; |
|
83 } |
|
84 |
|
85 EXPORT_C void RVPbkContactFieldDefaultPriorities::InternalizeL |
|
86 (const TDesC8& aBuffer) |
|
87 { |
|
88 iDefaultTypes.Reset(); |
|
89 |
|
90 RDesReadStream readStream(aBuffer); |
|
91 readStream.PushL(); |
|
92 |
|
93 // Version number |
|
94 const TInt vsn = readStream.ReadUint8L(); |
|
95 __ASSERT_ALWAYS(vsn == KPriorityArrayStatic::KArrayVersionNumber, |
|
96 VPbkError::Panic(VPbkError::EInvalidTypeParameter)); |
|
97 |
|
98 // Read count of elements |
|
99 TInt count = readStream.ReadUint8L(); |
|
100 |
|
101 // Read elements |
|
102 for (TInt i = 0; i < count; ++i) |
|
103 { |
|
104 TVPbkDefaultType type = (TVPbkDefaultType) readStream.ReadUint8L(); |
|
105 User::LeaveIfError(iDefaultTypes.Append(type)); |
|
106 } |
|
107 |
|
108 CleanupStack::PopAndDestroy(&readStream); |
|
109 } |
|
110 |
|
111 // End of File |