NlMakesis Y-Browser Y-Tasks
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
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)
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?
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 ?!
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...
Forum posts: 1232
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)
Forum posts: 159
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?
Forum posts: 2
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 ?!
Forum posts: 1232
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...