1 // Copyright (c) 2001-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef __WSPENCODER_H__
23 #define __WSPENCODER_H__
26 #include <f32file.h> // RFs
27 #include <badesca.h> // arrays etc.
28 #include <stringpool.h>
37 /** Due to failure to call StartValueLength function */
38 EWspCodecPanicStartValueLengthNotCalled=0,
39 /** Due to failure to call EndValueLength matching a call to StartValueLength */
40 EWspCodecPanicEndValueLengthNotCalled,
41 /** Due to failure to call StartHeaderL function */
42 EWspCodecPanicStartHeaderLNotCalled,
43 /** Due to StartHeaderL function being called twice without EndHeaderL */
44 EWspCodecPanicStartHeaderCalledTwice,
45 /** Due to parameter Token not having the top bit set */
46 EWspCodecPanicInvalidToken
50 This class can be used to encode one header field at a time,
51 with all its values and parameters.
53 It has no knowledge of encoding the BNF of a particular header field, but
54 the functions provided can be used in combination, producing an 8-bit buffer
55 containing the encoded header.
57 Intended usage would be to call a series of functions. The first one being StartHeader,
58 The final one being EndHeader, which would return a buffer containing
59 the complete encoded header field.
61 encoder->StartHeaderL();
62 encoder->AddLongIntL();
63 encoder->AddTextStringL();
64 HBufC8* output = encoder->EndHeaderL();
68 class CWspHeaderEncoder : public CBase
71 IMPORT_C static CWspHeaderEncoder* NewL();
73 IMPORT_C static CWspHeaderEncoder* NewLC();
76 IMPORT_C virtual ~CWspHeaderEncoder();
78 IMPORT_C void StartHeaderL(TUint8 aToken);
81 IMPORT_C void StartHeaderL(const TDesC8& aString);
83 IMPORT_C void StartHeaderL(const RStringF aString);
86 IMPORT_C HBufC8* EndHeaderL();
90 IMPORT_C void AddIntegerL(const TUint aInt);
93 IMPORT_C void AddShortIntL(const TUint8 aValue);
95 IMPORT_C void AddShortLengthL(const TUint8 aValue);
98 IMPORT_C void AddLongIntL(const TUint32 aValue);
101 IMPORT_C void AddUintVarL(const TUint aInt);
104 IMPORT_C void AddTextStringL(const RString& aText);
106 IMPORT_C void AddTextStringL(const TDesC8& aText);
108 IMPORT_C void AddDateL(const TDateTime aDate);
110 IMPORT_C void AddTokenL(const TUint8 aToken);
112 IMPORT_C void AddTokenTextL(const TDesC8& aTokenText);
114 IMPORT_C void AddDataL(const TDesC8& aData);
118 IMPORT_C void StartValueLengthL();
120 IMPORT_C void EndValueLengthL();
133 Array for storing the partial encoded header.
134 Each time StartValueLength is called a new array
135 element is used. When EndValueLength is called,
136 the array is decremented, data from the last
137 element being added to the one before.
139 RPointerArray<CDesC8Array> iArray;
142 Value incremented as the encoded header increases in size.
143 Used to allocate the buffer for storing the final
144 encoded header, output when EndHeader is called.
150 Class encapsulating primitive encoding methods which are defined in the WSP standard.
151 Input will be encoded and returned in an 8 bit buffer.
155 class TWspPrimitiveEncoder
158 IMPORT_C static TUint8 ShortInt(const TUint8 aValue);
160 IMPORT_C static HBufC8* LongIntL(const TUint32 aValue);
162 IMPORT_C static HBufC8* UintVarL(const TUint32 aInt);
164 IMPORT_C static HBufC8* TextStringL(const RString aText);
166 IMPORT_C static HBufC8* TextStringL(const TDesC8& aText);
168 IMPORT_C static HBufC8* DateL(const TDateTime aDate);
171 #endif // __WSPENCODER_H__