// Data lengths are not part of the encoded data, but since they are synch-safe
// integers they will be never actually encoded.
ByteVector frameData = data.mid(Frame::Header::size(version), header->frameSize());
- SynchData::decode(frameData);
+ frameData = SynchData::decode(frameData);
data = data.mid(0, Frame::Header::size(version)) + frameData;
}
return v;
}
-void SynchData::decode(ByteVector &data)
+ByteVector SynchData::decode(const ByteVector &data)
{
- char *n = data.data();
- const char *o = data.data();
- const char *end = o + data.size();
+ ByteVector result = data;
- if(data.size() <= 0)
- return;
+ ByteVector pattern(2, char(0));
+ pattern[0] = '\xFF';
+ pattern[1] = '\x00';
- while(o < end - 1) {
- *n++ = *o;
- if(o[0] == '\xFF' && o[1] == '\x00')
- o++;
- o++;
- }
- *n++ = *o;
-
- data.resize(n - data.data());
+ return result.replace(pattern, '\xFF');
}
TAGLIB_EXPORT ByteVector fromUInt(uint value);
/*!
- * Deunsynchronize the data (in-place).
+ * Convert the data from unsynchronized data to its original format.
*/
- TAGLIB_EXPORT void decode(ByteVector &data);
+ TAGLIB_EXPORT ByteVector decode(const ByteVector &input);
}
}
{
ByteVector data = origData;
- if(d->header.unsynchronisation() && d->header.majorVersion() <= 3) {
- SynchData::decode(data);
- }
+ if(d->header.unsynchronisation() && d->header.majorVersion() <= 3)
+ data = SynchData::decode(data);
uint frameDataPosition = 0;
uint frameDataLength = data.size();