Reading headers in a WSP buffer

TWspField object holds the name and value pair of the WSP header field. TWspHeaderSegmenter pulls the header / value pair out of the WSP buffer (into TWspField). Call TWspHeaderSegmenter::NextL() to iterate through the WSP buffer. It calls TWspPrimitiveDecoder.

CWspHeaderEncoder allows you to encode the values and parameters of the header field. It creates one header at a time from the name / value pairs.

The following are the steps to encode the WSP header:


  1. Create a header encoder object.
    //creates a pointer to CWspHeaderEncoder object
    CWspHeaderEncoder* primEncoder = CWspHeaderEncoder::NewLC();

  2. Start a new encoded header to encode the parameter value.
    // start a new encoded header
    primEncoder->StartHeaderL(0x27);

  3. Call CWspHeaderEncoder::StartValueLengthL() 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.
    primEncoder->StartValueLengthL();

  4. Encode the header field and add it to the encoded field. Note: The appropriate WSP method is used for encoding the header field of a data type such as integer, date, text string and so on.
    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);

  5. Call CWspHeaderEncoder::EndValuesLengthL() at the time of header construction when ValueLength can be calculated.

  6. Assuming that the length of the header encodings has been calculated and added to the encoder field, call CWspHeaderEncoder::EndValuesLengthL().
    primEncoder->EndValueLengthL();

  7. Call CWspHeaderEncoder::EndHeaderL(), to complete the header encoding. This completes and returns the encoded header field's 8 bit buffer. EndHeaderL() panics if EndValueLengthL() is not called after CWspHeaderEncoder::StartValueLengthL().
    HBufC8* buf = primEncoder->EndHeaderL();

    This returns a pointer to the buffer containing the encoded field.