encodeSigned static method

Uint8List encodeSigned(
  1. int n
)

Encodes an int into a LEB128 signed integer.

Implementation

static Uint8List encodeSigned(int n) {
  var more = true;
  var parts = <int>[];

  while (more) {
    var byte = n & 0x7F;
    n = _platform.shiftRightInt(n, 7);

    if (n == 0 && (byte & 0x40) == 0) {
      more = false;
    } else if (n == -1 && (byte & 0x40) > 0) {
      more = false;
    } else {
      byte |= 0x80;
    }

    parts.add(byte);
  }

  return Uint8List.fromList(parts);
}