/// <summary>
 /// Compare a buffer and a byte array for equality.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="offset">The offset into the left buffer.</param>
 /// <param name="compare">The compare byte array.</param>
 /// <returns>True if the buffers are equal.</returns>
 public static bool EqualBuffer(this SafeBuffer buffer, int offset, byte[] compare)
 {
     using (var compare_buffer = compare.ToBuffer())
     {
         return(buffer.EqualBuffer(offset, compare_buffer, 0, compare.Length));
     }
 }
Example #2
0
 /// <summary>
 /// Find a byte array in a buffer. Returns all instances of the compare array.
 /// </summary>
 /// <param name="buffer">The buffer to find the data in.</param>
 /// <param name="start_offset">Start offset in the buffer.</param>
 /// <param name="compare">The comparison byte array.</param>
 /// <returns>A list of offsets into the buffer where the compare was found.</returns>
 public static IEnumerable <int> FindBuffer(this SafeBuffer buffer, int start_offset, byte[] compare)
 {
     using (var compare_buffer = compare.ToBuffer()) {
         int max_length = buffer.GetLength() - compare.Length - start_offset;
         for (int i = 0; i < max_length; ++i)
         {
             if (buffer.EqualBuffer(start_offset + i, compare_buffer, 0, compare.Length))
             {
                 yield return(i + start_offset);
             }
         }
     }
 }