validateBytes static method

void validateBytes(
  1. Iterable<int> bytes, {
  2. String? onError,
})

Validates a list of integers representing bytes.

Ensures that each integer in the provided bytes list falls within the valid byte range (0 to 255). If any byte is outside this range, throws an ArgumentException with a descriptive error message.

Parameters:

  • bytes: A List of integers representing bytes to be validated.

Throws:

Implementation

static void validateBytes(Iterable<int> bytes, {String? onError}) {
  for (int i = 0; i < bytes.length; i++) {
    final int byte = bytes.elementAt(i);
    if (byte < 0 || byte > mask8) {
      throw ArgumentException(
          "${onError ?? "Invalid bytes"} at index $i $byte");
    }
  }
}