permute method

  1. @override
Uint8List permute(
  1. Uint8List instance
)
override

Generates another instance with some deterministic function.

The only exception is Kind.forNull (because it has no other instances).

Implementation

@override
Uint8List permute(Uint8List instance) {
  final result = Uint8List.fromList(instance);
  for (var i = result.length - 1; i >= 0; i--) {
    final byte = result[i];
    final newByte = 0xFF & (byte + 1);
    result[i] = newByte;
    if (newByte > 0) {
      return result;
    }
  }

  var newLength = instance.length + 1;

  final maxLength = length?.max;
  if (maxLength != null && instance.length == maxLength) {
    newLength = length?.min ?? 0;
  }

  return Uint8List(newLength);
}