behaviour of bytevector
Lukáš Lalinský
lalinsky at gmail.com
Wed Apr 21 21:25:08 CEST 2010
On Wed, Apr 21, 2010 at 9:01 PM, Matthieu Riolo
<matthieu.riolo at googlemail.com> wrote:
> Hello everybody
> I've just an small question but the problem is it really confusing me. I
> wrote an obj-c wrapper around the taglib class and I tried to integrate the
> Ogg Vorbis METADATA_BLOCK_PICTURE into the wrapper. I tried to work
> ByteVector but it seems that it does not behaviour like I thought. But maybe
> I just did not understand what the idea is behind ByteVector. For me it was
> clear that the class just manipulates the memory in a comfortable way.
> However, I seem to be unabled to put the complete data into memory!
>
> NSLog(@"%u",
> TagLib::String(TagLib::ByteVector(TagLib::ByteVector::fromUInt(10,
> true))).size());
> The code above will return 1! I recognized this problem as I tried to set 4
> bytes long integervalues with the quantity of 0. It occurs that the
> ByteVector contains the correct datasize but no data. This way ByteVector is
> always empty and will not append any data to his content (even if he resize
> correct).
>
> So me question is: Did I missed something? Or did I just run over a strange
> obj-c vs c++ case? For me it's important to know if this "strip" effect is
> wished or not. Because in me case it is absolutly in the way.
The problem is conversion of a byte vector with NULL bytes to a string.
I'm not sure if this is a copy&paste error in your example, but the
code should return 0. ByteVector::fromUInt(10, true) creates a byte
vector with four bytes 0x00 0x00 0x00 0x0A. The second
ByteVector(byteVector) creates a copy, so it's useless in this case.
String(ByteVector("\x00\x00\x00\x0A", 4)) tries to convert the bytes
into a string using Latin-1. It sees \x00 as the first character, so
it stops parsing it. The result is an empty string.
Btw, if you use ByteVector::fromUInt(10, false), the byte order would
be reversed and you would get a string with one character (ASCII code
\x0A).
Lukas
More information about the taglib-devel
mailing list