ExtensionMethods.cs 557 B

1234567891011121314151617181920212223
  1. namespace TftpServer.Utils
  2. {
  3. internal static class ExtensionMethods
  4. {
  5. public static int ScanNullTerminated(this byte[] bytes, long offset)
  6. {
  7. return ScanTo(bytes, offset, 0);
  8. }
  9. public static int ScanTo(this byte[] bytes, long offset, byte match)
  10. {
  11. for (var i = offset; i < bytes.Length; i++)
  12. {
  13. if (bytes[i] == match)
  14. {
  15. return (int)(i - offset);
  16. }
  17. }
  18. return -1;
  19. }
  20. }
  21. }