writeIntLE function

Uint8List writeIntLE(
  1. dynamic value,
  2. int byteLength
)

Implementation

Uint8List writeIntLE(dynamic value, int byteLength) {
  var bn = bnToBn(value);

  List<int> pipe = [];
  var i = 0;
  var mul = BigInt.from(256);
  var sub = BigInt.zero;
  var byte = (bn % mul).toInt();
  pipe.add(byte);
  while (++i < byteLength) {
    if (bn < BigInt.zero && sub == BigInt.zero && byte != 0) {
      sub = BigInt.one;
    }
    byte = ((bn ~/ mul - sub) % BigInt.from(256)).toInt();
    pipe.add(byte);
    mul *= BigInt.from(256);
  }

  return Uint8List.fromList(pipe);
}