|
1 // Copyright (c) 2003-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 // Name : MessageWriter.cpp |
|
15 // Part of : compressor |
|
16 // Interface : |
|
17 // SigComp message writer |
|
18 // Version : 1.0 |
|
19 // |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <badesca.h> |
|
26 |
|
27 #include "MessageWriter.h" |
|
28 |
|
29 /** Message delimeter, appended whe streaming protocol is enabled */ |
|
30 static const TUint16 KMessageDelimeter = 0xffff; |
|
31 |
|
32 CMessageWriter::CMessageWriter(CBufBase* aBuffer, TBool aStreamBasedProtocol) |
|
33 :iBuffer(aBuffer), iStreamBasedProtocol(aStreamBasedProtocol), |
|
34 iCount(0) |
|
35 { |
|
36 } |
|
37 |
|
38 void CMessageWriter::WriteByteL(TInt aByte) |
|
39 { |
|
40 TUint8 tmp; |
|
41 |
|
42 if(iStreamBasedProtocol) |
|
43 { |
|
44 if(aByte == 0xFF) |
|
45 { |
|
46 iCount++; |
|
47 } |
|
48 else |
|
49 { |
|
50 if(iCount) |
|
51 { |
|
52 iCount--; |
|
53 |
|
54 tmp = 0xFF; |
|
55 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
56 tmp = static_cast<TUint8>(iCount); |
|
57 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
58 |
|
59 for(TInt i=0; i<(iCount); i++) |
|
60 { |
|
61 tmp = 0xFF; |
|
62 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
63 } |
|
64 |
|
65 iCount = 0; |
|
66 tmp = static_cast<TUint8>(aByte); |
|
67 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
68 } |
|
69 else |
|
70 { |
|
71 tmp = static_cast<TUint8>(aByte); |
|
72 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
73 } |
|
74 } |
|
75 } |
|
76 else |
|
77 { |
|
78 tmp = static_cast<TUint8>(aByte); |
|
79 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
80 } |
|
81 } |
|
82 |
|
83 void CMessageWriter::WriteBlockL(const TDesC8& aBlock) |
|
84 { |
|
85 for(TInt i=0; i<aBlock.Length(); i++) |
|
86 { |
|
87 WriteByteL(aBlock[i]); |
|
88 } |
|
89 } |
|
90 |
|
91 void CMessageWriter::FlushAndTerminateL() |
|
92 { |
|
93 if(iStreamBasedProtocol) |
|
94 { |
|
95 if(iCount) |
|
96 { |
|
97 TUint8 tmp; |
|
98 |
|
99 // this code is not covered, because there is no way for deflate compressor |
|
100 // to output FF at the end of compressed message, the EOS character encoding |
|
101 // flushes all FFs in WriteByteL() |
|
102 // I left the code there, as it may be usefull for other compressors. |
|
103 |
|
104 iCount--; |
|
105 |
|
106 tmp = 0xFF; |
|
107 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
108 tmp = static_cast<TUint8>(iCount); |
|
109 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
110 |
|
111 for(TInt i=0; i<(iCount); i++) |
|
112 { |
|
113 tmp = 0xFF; |
|
114 iBuffer->InsertL(iBuffer->Size(), &tmp, 1); |
|
115 } |
|
116 iCount = 0; |
|
117 } |
|
118 iBuffer->InsertL(iBuffer->Size(), &KMessageDelimeter, 2); |
|
119 } |
|
120 } |