encodeUnsigned static method

Uint8List encodeUnsigned(
  1. int n
)

Encodes an int into LEB128 unsigned integer.

Implementation

static Uint8List encodeUnsigned(int n) {
  if (n < 0) {
    n = n.abs();
  }

  var size = (n.toRadixString(2).length / 7.0).ceil();
  var parts = <int>[];
  var i = 0;

  while (i < size) {
    var part = n & 0x7F;
    n = _platform.shiftRightInt(n, 7);
    parts.add(part);

    ++i;
  }

  for (var i = 0; i < parts.length - 1; i++) {
    parts[i] |= 0x80;
  }

  return Uint8List.fromList(parts);
}