frameSyncBytes[0] = frameSyncBytes[1];
frameSyncBytes[1] = buffer[i];
if(isFrameSync(frameSyncBytes)) {
- Header header(this, position + i - 1, true);
+ const Header header(this, position + i - 1, true);
if(header.isValid())
return position + i - 1;
}
frameSyncBytes[1] = frameSyncBytes[0];
frameSyncBytes[0] = buffer[i];
if(isFrameSync(frameSyncBytes)) {
- Header header(this, position + i, true);
+ const Header header(this, position + i, true);
if(header.isValid())
return position + i + header.frameLength();
}
if(readBlock(headerID.size()) == headerID)
return 0;
- Header firstHeader(this, 0, true);
+ const Header firstHeader(this, 0, true);
if(firstHeader.isValid())
return -1;
frameSyncBytes[0] = frameSyncBytes[1];
frameSyncBytes[1] = buffer[i];
if(isFrameSync(frameSyncBytes)) {
- Header header(this, position + i - 1, true);
+ const Header header(this, position + i - 1, true);
if(header.isValid())
return -1;
}
* \note This does not check the length of the vector, since this is an
* internal utility function.
*/
- inline bool isFrameSync(const ByteVector &bytes)
+ inline bool isFrameSync(const ByteVector &bytes, long offset = 0)
{
// 0xFF in the second byte is possible in theory, but it's very unlikely.
- const unsigned char b1 = bytes[0];
- const unsigned char b2 = bytes[1];
+ const unsigned char b1 = bytes[offset + 0];
+ const unsigned char b2 = bytes[offset + 1];
return (b1 == 0xFF && b2 != 0xFF && (b2 & 0xE0) == 0xE0);
}