Week 23 contribution of PDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License
"Eclipse Public License v1.0" which accompanies this distribution,
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
Nokia Corporation - initial contribution.
Contributors:
-->
<!DOCTYPE task
PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="GUID-4FE5CA06-8C3A-4AC1-80CE-4418AC55937A" xml:lang="en"><title>Reading
headers in a WSP buffer</title><shortdesc><codeph>TWspField</codeph> object holds the name and value pair
of the WSP header field. <codeph>TWspHeaderSegmenter</codeph> pulls the header
/ value pair out of the WSP buffer (into <codeph>TWspField</codeph>). Call <codeph>TWspHeaderSegmenter::NextL()</codeph> to
iterate through the WSP buffer. It calls <codeph>TWspPrimitiveDecoder</codeph>.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
<prereq id="GUID-333175CE-6D40-4F5C-9AD8-122A383CA3EF"> <p><xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita"><apiname>CWspHeaderEncoder</apiname></xref> allows you to encode
the values and parameters of the header field. It creates one header at a
time from the name / value pairs.</p> </prereq>
<context id="GUID-CAFFF446-43D5-440C-9B32-C3B9A518D2D3"> <p>The following are the steps to encode the WSP header:</p>
</context>
<steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-10-1-11-1-1-6-1-5-1-5-1-9-1-3-1-3-3">
<step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-10-1-11-1-1-6-1-5-1-5-1-9-1-3-1-3-3-1"><cmd/>
<info>Create a header encoder object.</info>
<stepxmp><codeblock xml:space="preserve">//creates a pointer to CWspHeaderEncoder object
CWspHeaderEncoder* primEncoder = CWspHeaderEncoder::NewLC();</codeblock></stepxmp>
</step>
<step id="GUID-C40D9259-C67F-4DA8-B524-A29E3BE2D0E0"><cmd/>
<info>Start a new encoded header to encode the parameter value. </info>
<stepxmp><codeblock xml:space="preserve">// start a new encoded header
primEncoder->StartHeaderL(0x27);</codeblock></stepxmp>
</step>
<step id="GUID-69650498-F216-4D21-B799-983B89022FA3"><cmd/>
<info>Call <xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita#GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37/GUID-D35C01C4-10A9-3BED-88F8-695DAC6411B7"><apiname>CWspHeaderEncoder::StartValueLengthL()</apiname></xref> to calculate
the length of encodings that are added subsequently. The value calculated,
is stored as part of the encoded string, as specified in the WSP standard. </info>
<stepxmp><codeblock xml:space="preserve">primEncoder->StartValueLengthL();</codeblock></stepxmp>
</step>
<step id="GUID-4958F0F4-1A49-4E3E-81F5-196DF68F253E"><cmd/>
<info>Encode the header field and add it to the encoded field. </info>
<info> <b>Note</b>: The appropriate WSP method is used for encoding the header
field of a data type such as integer, date, text string and so on. </info>
<stepxmp><codeblock xml:space="preserve">primEncoder->AddIntegerL(0x7F);
primEncoder->AddUintVarL(0xff);
primEncoder->AddLongIntL(999999);
_LIT8(KString, "WSP Encode: String");
primEncoder->AddTextStringL(KString);
TDateTime time(2006,EMarch,20,06,36,30,000000); //create a date time object
primEncoder->AddDateL(time); // add
TUInt intVal=489;
primEncoder->AddLTokenL(intVal);
_LIT8(KTokenText, "WSP Encode: Token Text");
primEncoder->AddLTokenTextL(KTokenText);</codeblock></stepxmp>
</step>
<step id="GUID-E99EF950-7080-4718-98FD-69DA9E8074DD"><cmd/>
<info>Call <xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita#GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37/GUID-80F4AA16-53D6-3836-A048-DADCDFEF4652"><apiname>CWspHeaderEncoder::EndValuesLengthL()</apiname></xref> at the
time of header construction when ValueLength can be calculated.</info>
</step>
<step id="GUID-3A70308A-ACCA-4059-9D26-D82A70B610BD"><cmd/>
<info>Assuming that the length of the header encodings has been calculated
and added to the encoder field, call <xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita#GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37/GUID-80F4AA16-53D6-3836-A048-DADCDFEF4652"><apiname>CWspHeaderEncoder::EndValuesLengthL()</apiname></xref>.</info>
<stepxmp><codeblock xml:space="preserve">primEncoder->EndValueLengthL();</codeblock></stepxmp>
</step>
<step id="GUID-9DEE2868-591D-488B-AAC9-D12EF2936CC2"><cmd/>
<info>Call <xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita#GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37/GUID-68A186E8-030B-3A0E-BFF0-ACCAD81C7F3D"><apiname>CWspHeaderEncoder::EndHeaderL()</apiname></xref>, to complete
the header encoding. This completes and returns the encoded header field's
8 bit buffer. <codeph>EndHeaderL()</codeph> panics if <codeph>EndValueLengthL()</codeph> is
not called after <xref href="GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37.dita#GUID-8E0D4BBE-BD06-396F-9517-45F9BFCDEF37/GUID-D35C01C4-10A9-3BED-88F8-695DAC6411B7"><apiname>CWspHeaderEncoder::StartValueLengthL()</apiname></xref>. </info>
<stepxmp><codeblock xml:space="preserve">HBufC8* buf = primEncoder->EndHeaderL();</codeblock></stepxmp>
<stepresult><p>This returns a pointer to the buffer containing the encoded
field. </p></stepresult>
</step>
</steps>
</taskbody></task>