public void Find(FindByteDataOption findByteDataOption) { _startIndex = findByteDataOption.SearchStartIndex; _matchCase = findByteDataOption.MatchCase; FindByteDataEventArgs args = new FindByteDataEventArgs(); if (findByteDataOption.SearchBytes == null) { args.FoundPosition = -1; OnFindPositionFound(args); return; } if (findByteDataOption.SearchDirection == SearchDirection.Direction_Up) { args.FoundPosition = FindUp(findByteDataOption); } else { args.FoundPosition = FindDown(findByteDataOption); } OnFindPositionFound(args); }
public long FindDown(FindByteDataOption findByteDataOption) { while (_startIndex < _byteData.Length) { long bufferSize = FillBuffer(_buffer, _startIndex); int i = FindBuffer(_buffer, findByteDataOption.SearchBytes); if (i >= 0) { return(_startIndex + i); } else { _startIndex += _buffer.Length - findByteDataOption.SearchBytes.Length + 1; } } return(-1); }
public long FindUp(FindByteDataOption findByteDataOption) { while (_startIndex > 0) { long bufferSize = FillBufferUp(_buffer, _startIndex); int i = FindBuffer(_buffer, findByteDataOption.SearchBytes); if (i >= 0) { //return _startIndex - (_buffer.Length - i) + 1; return(_startIndex - (bufferSize - i) + 1); } else { _startIndex -= _buffer.Length - findByteDataOption.SearchBytes.Length + 1; } } return(-1); }