89
|
1 |
/*
|
|
2 |
* Copyright (c) 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 "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 |
*
|
92
|
14 |
* Description:
|
89
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "hsserializer.h"
|
93
|
18 |
#include <s32mem.h>
|
89
|
19 |
// -----------------------------------------------------------------------------
|
|
20 |
//
|
|
21 |
// -----------------------------------------------------------------------------
|
|
22 |
//
|
92
|
23 |
RBuf8 &operator <<(RBuf8 &dst, const QPixmap &src)
|
89
|
24 |
{
|
|
25 |
QByteArray buffer;
|
|
26 |
QDataStream stream(&buffer, QIODevice::WriteOnly);
|
92
|
27 |
|
89
|
28 |
QT_TRYCATCH_LEAVING(stream << src);
|
|
29 |
const int dataLength(buffer.length());
|
92
|
30 |
const unsigned char *dataPtr(reinterpret_cast<const unsigned char *>(buffer.constData()));
|
|
31 |
if (dst.MaxLength() < dataLength) {
|
89
|
32 |
dst.ReAllocL(dataLength);
|
|
33 |
}
|
|
34 |
dst.Copy(dataPtr, dataLength);
|
|
35 |
return dst;
|
|
36 |
}
|
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
//
|
92
|
42 |
QPixmap &operator <<(QPixmap &dst, const TDesC8 &src)
|
89
|
43 |
{
|
92
|
44 |
QByteArray buffer(QByteArray::fromRawData(reinterpret_cast<const char *>(src.Ptr()),
|
|
45 |
src.Length()) );
|
|
46 |
|
89
|
47 |
QDataStream stream(&buffer, QIODevice::ReadOnly);
|
|
48 |
QT_TRYCATCH_LEAVING(stream >> dst);
|
|
49 |
return dst;
|
|
50 |
}
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
//
|
92
|
56 |
RBuf8 &operator <<(RBuf8 &dst, const QVariantHash &src)
|
89
|
57 |
{
|
|
58 |
QByteArray buffer;
|
|
59 |
QDataStream stream(&buffer, QIODevice::WriteOnly);
|
92
|
60 |
|
89
|
61 |
QT_TRYCATCH_LEAVING(stream << src);
|
92
|
62 |
const int dataLength(buffer.length());
|
|
63 |
const unsigned char *dataPtr(reinterpret_cast<const unsigned char *>(buffer.constData()));
|
|
64 |
if (dst.MaxLength() < dataLength) {
|
|
65 |
dst.ReAllocL(dataLength);
|
89
|
66 |
}
|
92
|
67 |
dst.Copy(dataPtr, dataLength);
|
89
|
68 |
return dst;
|
|
69 |
}
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
92
|
75 |
QVariantHash &operator <<(QVariantHash &dst, const TDesC8 &src)
|
89
|
76 |
{
|
92
|
77 |
QByteArray buffer(QByteArray::fromRawData(reinterpret_cast<const char *>(src.Ptr()),
|
|
78 |
src.Length()) );
|
|
79 |
|
89
|
80 |
QDataStream stream(&buffer, QIODevice::ReadOnly);
|
|
81 |
QT_TRYCATCH_LEAVING(stream >> dst);
|
|
82 |
return dst;
|
|
83 |
}
|
92
|
84 |
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
//
|
|
89 |
RBuf8 &operator <<(RBuf8 &dst, const QList<QVariantHash>& src)
|
|
90 |
{
|
|
91 |
QByteArray buffer;
|
|
92 |
QDataStream stream(&buffer, QIODevice::WriteOnly);
|
|
93 |
|
|
94 |
QT_TRYCATCH_LEAVING(stream << src);
|
|
95 |
|
|
96 |
if (dst.MaxLength() < buffer.length()) {
|
|
97 |
dst.ReAllocL(buffer.length());
|
|
98 |
}
|
|
99 |
dst.Copy(reinterpret_cast<const TUint8 *>(buffer.data()), buffer.length());
|
|
100 |
return dst;
|
|
101 |
}
|
|
102 |
|
|
103 |
// -----------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
// -----------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
QList<QVariantHash>& operator <<(QList<QVariantHash>& dst, const TDesC8 &src)
|
|
108 |
{
|
93
|
109 |
dst.clear();
|
|
110 |
|
|
111 |
QVariantHash item;
|
|
112 |
TRAP_IGNORE(
|
|
113 |
RDesReadStream srcStream(src);
|
|
114 |
int numOfItems(srcStream.ReadInt32L());
|
|
115 |
int bufferSize;
|
|
116 |
|
|
117 |
RBuf8 tmpBuff;
|
|
118 |
CleanupClosePushL(tmpBuff);
|
|
119 |
for (int iter(0); iter < numOfItems; ++iter) {
|
|
120 |
bufferSize = srcStream.ReadInt32L();
|
|
121 |
if (tmpBuff.MaxLength() < bufferSize) {
|
|
122 |
tmpBuff.ReAllocL(bufferSize);
|
|
123 |
}
|
|
124 |
item.clear();
|
|
125 |
if (0 < bufferSize) {
|
|
126 |
srcStream.ReadL(tmpBuff, bufferSize);
|
|
127 |
item << tmpBuff;
|
|
128 |
}
|
|
129 |
dst.append(item);
|
|
130 |
}
|
|
131 |
CleanupStack::PopAndDestroy(&tmpBuff));
|
92
|
132 |
return dst;
|
|
133 |
}
|