toBytes static method

List<int> toBytes(
  1. Iterable<int> bytes, {
  2. bool unmodifiable = false,
})

Ensures that each byte is properly represented as an 8-bit integer.

Performs a bitwise AND operation with a mask (mask8) to ensure that each byte in the input list is represented as an 8-bit integer.

Implementation

static List<int> toBytes(Iterable<int> bytes, {bool unmodifiable = false}) {
  final toBytes = bytes.map((e) => e & mask8).toList();
  if (unmodifiable) {
    return List<int>.unmodifiable(toBytes);
  }
  return toBytes;
}