toLittleEndian static method

ByteArray toLittleEndian(
  1. ByteArray value, [
  2. int offset = 0,
  3. int? length
])

Convert a byte array to little-endian format

Implementation

static ByteArray toLittleEndian(ByteArray value,
    [int offset = 0, int? length]) {
  length ??= value.length - offset;
  if (offset < 0 || offset > value.length) {
    throw ArgumentError('Invalid offset: $offset');
  }
  if (length < 0 || offset + length > value.length) {
    throw ArgumentError('Invalid length: $length');
  }
  final copy = Uint8List(length);
  copy.setRange(0, length, value, offset);
  for (int i = 0; i < (copy.length >> 1); i++) {
    final temp = copy[i];
    copy[i] = copy[copy.length - i - 1];
    copy[copy.length - i - 1] = temp;
  }
  return copy;
}