Using TDesC8 Class

Use TDescC8 for interfaces which takes binary data or explicit
narrow text, regardless of the build variant, but which does not need
to change the data.

Using
in a function interface

Interfaces which take binary data
or narrow text, use descriptors in the specification of that interface.
All 8 bit concrete descriptors are derived from TDesC8 which means that the interface can accept any 8 bit descriptor.

The following code fragment shows the most common function prototype
pattern.

void ClassX::foo(const TDesC8& anArg);

The use
of TDesC8 ensures that the data cannot be modified
through the descriptor; const is an extra guarantee
that the data cannot be changed.

Extract
leftmost part of data

The code fragment shows how the leftmost
part of data in a descriptor can be accessed, using the TDesC8::Left() member function.

The behaviour is the same for the build
independent variant, TDesC, replacing _LIT8 with _LIT, TBufC8 with TBufC and TPtrC8 with TPtrC.

_LIT8(KData,"abcdefg");
TBufC8<8> str(KData);
...
str.Left(4);

The call to Left() returns a non-modifiable pointer descriptor representing the data
string "abcd"; this has length 4. The original data
contained in, and represented by, the non-modifiable buffer descriptor str, is not changed in any way.

_LIT8(KData,"abcdefg");
TBufC8<8> str(KData);
...
str.Left(256);

This call to Left() returns a non-modifiable pointer descriptor representing the data
string "abcdefg", i.e. the whole content of the descriptor str; this has length 7.

Extract
rightmost part of data

The code fragment shows how the
rightmost part of data in a descriptor can be accessed, using the TDesC8::Right() member function.

The behaviour is
the same for the build independent variant, TDesC, replacing _LIT8 with _LIT, TBufC8 with TBufC and TPtrC8 with TPtrC.

_LIT8(KData,"abcdefg");
TBufC8<8> str(KData);
...
str.Right(4);

The call to Right() returns
a non-modifiable pointer descriptor representing the data string "defg"; this has length 4. The original data contained in,
and represented by, the non-modifiable buffer descriptor str, is not changed in any way.

_LIT8(KData,"abcdefg");
TBufC8<8> str(KData);
...
str.Right(256);

This call to Right() returns a non-modifiable pointer descriptor representing the data
string "abcdefg", i.e. the whole content of the descriptor str; this has length 7.

Extract
middle portion of the data

The code fragment shows how
a portion of data within a descriptor can be accessed, using the TDesC8::Mid() member function. Each call toMid() returns a non-modifiable pointer descriptor representing the selected
portions of data.

The behaviour is the same for the build independent
variant,TDesC, replacing _LIT8 with _LIT, TBufC8 withTBufC and TPtrC8 withTPtrC.