Conversion between TPtrC to TPtrC8

Login to reply to this topic.
Wed, 2008-03-05 05:51
Joined: 2008-03-05
Forum posts: 2

Hi All

I just got a doubt whether it is really possible to convert some non-modifiable pointer of type TPtrC to 8 bit TPtrC8 ?

TPtrC iPtrC;
TPtrC8 iPtrC8;

iPtrC8 <--> iPtrC possible ?

Thanks in Advance,
Venkat


Wed, 2008-03-05 10:03
Joined: 2004-11-29
Forum posts: 1232
Re: Conversion between TPtrC to TPtrC8

Why wouldn't it be possible?

TPtrC iPtrC;
TPtrC8 iPtrC8((TUint8*)iPtrC.Ptr(), iPtrC.Length()*2); //Either like this in constructor

iPtrC.Set((TUint16*)iPtrC8.Ptr(),iPtrC8.Length()/2); //Or like this after its created

make sure to do the /2 and *2 right.. a 8 bit descriptor with length 256 is only a 128 long 16 bit descriptor (ofcourse)

Thu, 2008-03-06 00:31
Joined: 2007-09-23
Forum posts: 159
Re: Conversion between TPtrC to TPtrC8

Do you think converting from a TPtrC8 to TPtrC16 or vice versa actually changes the data? Or were you concerned as they are C ptrs they cannot be reassigned to once pointing to something?

Tue, 2008-03-18 06:17
Joined: 2008-03-05
Forum posts: 2
Re: Conversion between TPtrC to TPtrC8

Hi.. I tried the same. But it is not returning the entire string. I guess there is some problem in length being specified.

I mean, if i have a value of "test" in TPtrC, it returns only "t" in TPtrC8.

Can you pl help ?!

Tue, 2008-03-18 09:07
Joined: 2004-11-29
Forum posts: 1232
Re: Conversion between TPtrC to TPtrC8

The data is still there.
Though, every second position would be 0, since we just re-casted the data in the 16 bit descriptor to this 8 bit one.

So if you try to access it as a zero terminated string, you would only get the "t" ofcourse.

You didn't say you wanted to convert the data, just that you wanted to convert the pointer.

If you want to convert the data, then ofcourse you would need to copy it to a new buffer for conversion.

if you use TDes8::Copy() (to for example a new RBuf or TBuf ) it will do a conversion that probably is the one you are expecting...

  • Login to reply to this topic.