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.

Context

The following are the steps to encode the WSP header:

Prerequisites

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.

Steps

  1. Create a header encoder object.

    Example:

    //creates a pointer to CWspHeaderEncoder object
    CWspHeaderEncoder* primEncoder = CWspHeaderEncoder::NewLC();
  2. Start a new encoded header to encode the parameter value.

    Example:

    // 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.

    Example:

    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.

    Example:

    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().

    Example:

    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().

    Example:

    HBufC8* buf = primEncoder->EndHeaderL();

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