validateBytes static method
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:
- ArgumentException if any byte is outside the valid range.
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");
}
}
}