Example #1
0
bool ShiftableBuffer::Sync(const byte_t* apPattern, size_t aNumBytes)
{
	if(aNumBytes < 1) throw ArgumentException(LOCATION, "Pattern must be at least 1 byte");

	size_t offset = SyncSubsequence(apPattern, aNumBytes, 0);
	bool res = (this->NumReadBytes() - offset) >= aNumBytes;
	if(offset > 0) this->AdvanceRead(offset);

	return res;
}
Example #2
0
bool ShiftableBuffer::Sync(const uint8_t* apPattern, size_t aNumBytes)
{
	if(aNumBytes < 1) {
		MACRO_THROW_EXCEPTION(ArgumentException, "Pattern must be at least 1 byte");
	}

	size_t offset = SyncSubsequence(apPattern, aNumBytes, 0);
	bool res = (this->NumReadBytes() - offset) >= aNumBytes;
	if(offset > 0) this->AdvanceRead(offset);

	return res;
}
Example #3
0
size_t ShiftableBuffer::SyncSubsequence(const uint8_t* apPattern, size_t aNumPatternBytes, size_t aOffset)
{
	size_t read_bytes = this->NumReadBytes() - aOffset;
	if(aNumPatternBytes > read_bytes) aNumPatternBytes = read_bytes;

	const uint8_t* pRead = this->ReadBuff() + aOffset;

	for(size_t i = 0; i < aNumPatternBytes; ++i) {
		if(apPattern[i] != pRead[i])
			return SyncSubsequence(apPattern, aNumPatternBytes, aOffset + 1);
	}

	return aOffset;
}