readLeb128SignedInt method

int readLeb128SignedInt({
  1. int bits = 64,
})

Reads a LEB128 signed integer.

  • bits (optional) argument specifies the number of bits in the integer. Default: 64

Implementation

int readLeb128SignedInt({int bits = 64}) {
  var result = 0;
  var shift = 0;

  var lastByte = 0;

  while (true) {
    var byte = readByte();
    result |= _platform.shiftLeftInt((byte & 0x7F), shift);
    shift += 7;

    if ((byte & 0x80) == 0) {
      break;
    }

    lastByte = byte;
  }

  if ((shift < bits) && (lastByte & 0x40) != 0) {
    if (_platform.supportsFullBitsShift) {
      result |= _platform.shiftLeftInt(-1, shift);
    } else {
      result = (BigInt.from(result) | (BigInt.from(-1) << shift)).toInt();
    }
  }

  return result;
}