|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <s32ucmp.h> |
|
17 #include "US_STD.H" |
|
18 |
|
19 EXPORT_C void ExternalizeL(TInt64 anInt64,RWriteStream& aStream) |
|
20 // |
|
21 // Write a 64-bit integer out to aStream. |
|
22 // |
|
23 { |
|
24 aStream.WriteUint32L(I64LOW(anInt64)); |
|
25 aStream.WriteUint32L(I64HIGH(anInt64)); |
|
26 } |
|
27 |
|
28 EXPORT_C void InternalizeL(TInt64& anInt64,RReadStream& aStream) |
|
29 // |
|
30 // Read a 64-bit integer in from aStream. |
|
31 // |
|
32 { |
|
33 TUint low=aStream.ReadUint32L(); |
|
34 TUint high=aStream.ReadUint32L(); |
|
35 anInt64 = MAKE_TINT64(high,low); |
|
36 } |
|
37 |
|
38 EXPORT_C void ExternalizeL(const TCheckedUid& aUid,RWriteStream& aStream) |
|
39 // |
|
40 // Write a checked uid type out to aStream. |
|
41 // |
|
42 { |
|
43 aStream.WriteL(aUid.Des()); |
|
44 } |
|
45 |
|
46 EXPORT_C void InternalizeL(TCheckedUid& aUid,RReadStream& aStream) |
|
47 // |
|
48 // Read a checked uid type in from aStream. |
|
49 // |
|
50 { |
|
51 TBuf8<sizeof(TCheckedUid)> buf; |
|
52 aStream.ReadL(buf); |
|
53 aUid.Set(buf); |
|
54 } |
|
55 |
|
56 EXPORT_C void ExternalizeL(TPoint aPoint,RWriteStream& aStream) |
|
57 // |
|
58 // Write a point out to aStream. |
|
59 // |
|
60 { |
|
61 aStream.WriteInt32L(aPoint.iX); |
|
62 aStream.WriteInt32L(aPoint.iY); |
|
63 } |
|
64 |
|
65 EXPORT_C void ExternalizeL(TSize aSize,RWriteStream& aStream) |
|
66 // |
|
67 // Write a size out to aStream. |
|
68 // |
|
69 { |
|
70 aStream.WriteInt32L(aSize.iWidth); |
|
71 aStream.WriteInt32L(aSize.iHeight); |
|
72 } |
|
73 |
|
74 EXPORT_C void ExternalizeL(const TRect& aRect,RWriteStream& aStream) |
|
75 // |
|
76 // Write a rectangle out to aStream. |
|
77 // |
|
78 { |
|
79 aStream<<aRect.iTl; |
|
80 aStream<<aRect.iBr; |
|
81 } |
|
82 |
|
83 EXPORT_C void InternalizeL(TPoint& aPoint,RReadStream& aStream) |
|
84 // |
|
85 // Read a point in from aStream. |
|
86 // |
|
87 { |
|
88 aPoint.iX=aStream.ReadInt32L(); |
|
89 aPoint.iY=aStream.ReadInt32L(); |
|
90 } |
|
91 |
|
92 EXPORT_C void InternalizeL(TSize& aSize,RReadStream& aStream) |
|
93 // |
|
94 // Read a size in from aStream. |
|
95 // |
|
96 { |
|
97 aSize.iWidth=aStream.ReadInt32L(); |
|
98 aSize.iHeight=aStream.ReadInt32L(); |
|
99 } |
|
100 |
|
101 EXPORT_C void InternalizeL(TRect& aRect,RReadStream& aStream) |
|
102 // |
|
103 // Read a rectangle in from aStream. |
|
104 // |
|
105 { |
|
106 aStream>>aRect.iTl; |
|
107 aStream>>aRect.iBr; |
|
108 } |
|
109 |
|
110 EXPORT_C void ExternalizeL(const TDesC8& aDes8,RWriteStream& aStream) |
|
111 // |
|
112 // Write an 8-bit descriptor out to aStream. |
|
113 // |
|
114 { |
|
115 TDesHeader header(aDes8); |
|
116 aStream<<header; |
|
117 aStream.WriteL(aDes8.Ptr(),aDes8.Length()); |
|
118 } |
|
119 |
|
120 EXPORT_C void ExternalizeL(const TDesC16& aDes16,RWriteStream& aStream) |
|
121 // |
|
122 // Write a 16-bit descriptor out to aStream. |
|
123 // |
|
124 { |
|
125 TDesHeader header(aDes16); |
|
126 aStream << header; |
|
127 |
|
128 #ifdef _UNICODE |
|
129 // In the Unicode build, compress the data using the Standard Unicode Compression Scheme. |
|
130 TMemoryUnicodeSource source(aDes16.Ptr()); |
|
131 TUnicodeCompressor compressor; |
|
132 compressor.CompressL(aStream,source,KMaxTInt,aDes16.Length()); |
|
133 |
|
134 #else |
|
135 aStream.WriteL(aDes16.Ptr(),aDes16.Length()); |
|
136 #endif |
|
137 } |
|
138 |
|
139 EXPORT_C void InternalizeL(TDes8& aDes8,RReadStream& aStream) |
|
140 // |
|
141 // Read an 8-bit descriptor in from aStream. |
|
142 // |
|
143 { |
|
144 TDesInternalizer interL; |
|
145 aStream>>interL.Header(); |
|
146 interL(aDes8,aStream); |
|
147 } |
|
148 |
|
149 EXPORT_C void InternalizeL(TDes16& aDes16,RReadStream& aStream) |
|
150 // |
|
151 // Read a 16-bit descriptor in from aStream. |
|
152 // |
|
153 { |
|
154 TDesInternalizer interL; |
|
155 aStream>>interL.Header(); |
|
156 interL(aDes16,aStream); |
|
157 } |
|
158 |
|
159 EXPORT_C HBufC8* HBufC8::NewL(RReadStream& aStream,TInt aMaxLength) |
|
160 /** |
|
161 Creates, and returns a pointer to, a new 8-bit heap descriptor that has been |
|
162 initialised with data from the specified read stream; leaves on failure. |
|
163 |
|
164 Data is assigned to the new descriptor from the specified stream. This variant |
|
165 assumes that the stream contains the length of the data followed by the data |
|
166 itself. |
|
167 |
|
168 The requested maximum length of the descriptor buffer is the length value taken |
|
169 from the stream. Note that the size of the allocated cell, and the resulting |
|
170 maximum length of the descriptor, may be larger than requested due to the way |
|
171 memory is allocated in Symbian OS. This rounding up effect is also dependent |
|
172 on platform and build type. |
|
173 |
|
174 Note that: |
|
175 1. To use this variant, project files must also link against estor.lib |
|
176 2. The length of the data in the stream is represented by a TCardinality object. |
|
177 |
|
178 @param aStream The stream from which the data length and the data to be |
|
179 assigned to the new descriptor, are taken. |
|
180 @param aMaxLength The upper limit on the length of data that the descriptor is |
|
181 to represent. |
|
182 |
|
183 @return A pointer to the new 8-bit heap descriptor. The function leaves, |
|
184 if the new 8-bit heap descriptor cannot be created. |
|
185 |
|
186 @leave KErrOverflow if the length of the data as read from the stream is |
|
187 greater than the upper limit as specified by aMaxLength. |
|
188 |
|
189 @panic USER 30, if aMaxLength is negative. |
|
190 |
|
191 @see TCardinality |
|
192 */ |
|
193 { |
|
194 HBufC8* buf8=NewLC(aStream,aMaxLength); |
|
195 CleanupStack::Pop(); |
|
196 return buf8; |
|
197 } |
|
198 |
|
199 EXPORT_C HBufC8* HBufC8::NewLC(RReadStream& aStream,TInt aMaxLength) |
|
200 /** |
|
201 Creates, adds a pointer onto the cleanup stack, and returns a pointer to, |
|
202 a new 8-bit heap descriptor that has been initialised with data from the |
|
203 specified read stream; leaves on failure. |
|
204 |
|
205 Data is assigned to the new descriptor from the specified stream. This variant |
|
206 assumes that the stream contains the length of the data followed by the data |
|
207 itself. |
|
208 |
|
209 The requested maximum length of the descriptor buffer is the length value taken |
|
210 from the stream. Note that the size of the allocated cell, and the resulting |
|
211 maximum length of the descriptor, may be larger than requested due to the way |
|
212 memory is allocated in Symbian OS. This rounding up effect is also dependent |
|
213 on platform and build type. |
|
214 |
|
215 Note that: |
|
216 1. To use this variant, project files must also link against estor.lib |
|
217 2. The length of the data in the stream is represented by a TCardinality object. |
|
218 |
|
219 @param aStream The stream from which the data length and the data to be |
|
220 assigned to the new descriptor, are taken. |
|
221 @param aMaxLength The upper limit on the length of data that the descriptor is |
|
222 to represent. |
|
223 |
|
224 @return A pointer to the new 8-bit heap descriptor. The function leaves, |
|
225 if the new 8-bit heap descriptor cannot be created. |
|
226 |
|
227 @leave KErrOverflow if the length of the data as read from the stream is |
|
228 greater than the upper limit as specified by aMaxLength. |
|
229 |
|
230 @panic USER 30, if aMaxLength is negative. |
|
231 |
|
232 @see TCardinality |
|
233 */ |
|
234 { |
|
235 TDesInternalizer interL; |
|
236 aStream>>interL.Header(); |
|
237 TInt len=interL.Header().Length(); |
|
238 if (len>aMaxLength) |
|
239 __LEAVE(KErrOverflow); |
|
240 // |
|
241 HBufC8* buf8=NewLC(len); |
|
242 TPtr8 ptr8=buf8->Des(); |
|
243 interL(ptr8,aStream); |
|
244 return buf8; |
|
245 } |
|
246 |
|
247 EXPORT_C HBufC16* HBufC16::NewL(RReadStream& aStream,TInt aMaxLength) |
|
248 /** |
|
249 Creates, and returns a pointer to, a new 16-bit heap descriptor that has been |
|
250 initialised with data from the specified read stream; leaves on failure. |
|
251 |
|
252 Data is assigned to the new descriptor from the specified stream. This variant |
|
253 assumes that the stream contains the length of the data followed by the data |
|
254 itself. |
|
255 |
|
256 The requested maximum length of the descriptor buffer is the length value taken |
|
257 from the stream. Note that the size of the allocated cell, and the resulting |
|
258 maximum length of the descriptor, may be larger than requested due to the way |
|
259 memory is allocated in Symbian OS. This rounding up effect is also dependent |
|
260 on platform and build type. |
|
261 |
|
262 Note that: |
|
263 1. To use this variant, project files must also link against estor.lib |
|
264 2. The length of the data in the stream is represented by a TCardinality object. |
|
265 |
|
266 @param aStream The stream from which the data length and the data to be |
|
267 assigned to the new descriptor, are taken. |
|
268 @param aMaxLength The upper limit on the length of data that the descriptor is |
|
269 to represent. |
|
270 |
|
271 @return A pointer to the new 16-bit heap descriptor. The function leaves, |
|
272 if the new 16-bit heap descriptor cannot be created. |
|
273 |
|
274 @leave KErrOverflow if the length of the data as read from the stream is |
|
275 greater than the upper limit as specified by aMaxLength. |
|
276 |
|
277 @panic USER 18, if aMaxLength is negative. |
|
278 |
|
279 @see TCardinality |
|
280 */ |
|
281 { |
|
282 HBufC16* buf16=NewLC(aStream,aMaxLength); |
|
283 CleanupStack::Pop(); |
|
284 return buf16; |
|
285 } |
|
286 |
|
287 EXPORT_C HBufC16* HBufC16::NewLC(RReadStream& aStream,TInt aMaxLength) |
|
288 /** |
|
289 Creates, adds a pointer onto the cleanup stack, and returns a pointer to, |
|
290 a new 16-bit heap descriptor that has been initialised with data from the |
|
291 specified read stream; leaves on failure. |
|
292 |
|
293 Data is assigned to the new descriptor from the specified stream. This variant |
|
294 assumes that the stream contains the length of the data followed by the data |
|
295 itself. |
|
296 |
|
297 The requested maximum length of the descriptor buffer is the length value taken |
|
298 from the stream. Note that the size of the allocated cell, and the resulting |
|
299 maximum length of the descriptor, may be larger than requested due to the way |
|
300 memory is allocated in Symbian OS. This rounding up effect is also dependent |
|
301 on platform and build type. |
|
302 |
|
303 Note that: |
|
304 1. To use this variant, project files must also link against estor.lib |
|
305 2. The length of the data in the stream is represented by a TCardinality object. |
|
306 |
|
307 @param aStream The stream from which the data length and the data to be |
|
308 assigned to the new descriptor, are taken. |
|
309 @param aMaxLength The upper limit on the length of data that the descriptor is |
|
310 to represent. |
|
311 |
|
312 @return A pointer to the new 16-bit heap descriptor. The function leaves, |
|
313 if the new 16-bit heap descriptor cannot be created. |
|
314 |
|
315 @leave KErrOverflow if the length of the data as read from the stream is |
|
316 greater than the upper limit as specified by aMaxLength. |
|
317 |
|
318 @panic USER 30, if aMaxLength is negative. |
|
319 |
|
320 @see TCardinality |
|
321 */ |
|
322 { |
|
323 TDesInternalizer interL; |
|
324 aStream>>interL.Header(); |
|
325 TInt len=interL.Header().Length(); |
|
326 if (len>aMaxLength) |
|
327 __LEAVE(KErrOverflow); |
|
328 // |
|
329 HBufC16* buf16=NewLC(len); |
|
330 TPtr16 ptr16=buf16->Des(); |
|
331 interL(ptr16,aStream); |
|
332 return buf16; |
|
333 } |
|
334 |
|
335 EXPORT_C void ExternalizeL(const CBufBase& aBuf,RWriteStream& aStream) |
|
336 // |
|
337 // Write a buffer out to aStream. |
|
338 // |
|
339 { |
|
340 TInt size=aBuf.Size(); |
|
341 aStream<<TCardinality(size); |
|
342 TInt pos=0; |
|
343 while (size>0) |
|
344 { |
|
345 TPtr8 seg=((CBufBase&)aBuf).Ptr(pos); |
|
346 TInt len=seg.Size(); |
|
347 aStream.WriteL(seg.Ptr(),len); |
|
348 size-=len; |
|
349 pos+=len; |
|
350 } |
|
351 } |
|
352 |
|
353 EXPORT_C void InternalizeL(CBufBase& aBuf,RReadStream& aStream) |
|
354 // |
|
355 // Read a buffer in from aStream. |
|
356 // |
|
357 { |
|
358 TCardinality card; |
|
359 aStream>>card; |
|
360 // |
|
361 aBuf.ResizeL(TInt(card)); |
|
362 TInt pos=0; |
|
363 for (;;) |
|
364 { |
|
365 TPtr8 seg=aBuf.Ptr(pos); |
|
366 TInt len=seg.Size(); |
|
367 if (len==0) |
|
368 return; |
|
369 // |
|
370 aStream.ReadL((TUint8*)seg.Ptr(),len); |
|
371 pos+=len; |
|
372 } |
|
373 } |
|
374 |
|
375 EXPORT_C void ArrayExternalizeCountL(TInt aCount,RWriteStream& aStream) |
|
376 // |
|
377 // Write an array's count out to aStream. |
|
378 // |
|
379 { |
|
380 aStream<<TCardinality(aCount); |
|
381 } |
|
382 |
|
383 EXPORT_C void DoExternalizeAllL(const CArrayFixBase& anArray,RWriteStream& aStream,TExternalizer<TAny> anExter) |
|
384 // |
|
385 // Write an array's contents out to aStream. |
|
386 // |
|
387 { |
|
388 for (TInt i=0,n=anArray.Count();i<n;i++) |
|
389 anExter(anArray.At(i),aStream); |
|
390 } |
|
391 |
|
392 EXPORT_C TInt ArrayInternalizeCountL(RReadStream& aStream) |
|
393 // |
|
394 // Read an array's count in from aStream. |
|
395 // |
|
396 { |
|
397 TCardinality card; |
|
398 aStream>>card; |
|
399 // |
|
400 return TInt(card); |
|
401 } |
|
402 |
|
403 EXPORT_C void DoInternalizeAllL(CArrayFixBase& anArray,RReadStream& aStream,TInternalizer<TAny> anInter) |
|
404 // |
|
405 // Read an array's contents in from aStream. |
|
406 // |
|
407 { |
|
408 for (TInt i=0,n=anArray.Count();i<n;i++) |
|
409 anInter(anArray.At(i),aStream); |
|
410 } |
|
411 |