code: function encodeBufferCommon(buffer, signed) {
    let signBit;
    let bitCount;
  
    if (signed) {
      signBit = bits.getSign(buffer);
      bitCount = signedBitCount(buffer);
    } else {
      signBit = 0;
      bitCount = unsignedBitCount(buffer);
    }
  
    const byteCount = Math.ceil(bitCount / 7);
    const result = bufs.alloc(byteCount);
  
    for (let i = 0; i < byteCount; i++) {
      const payload = bits.extract(buffer, i * 7, 7, signBit);
      result[i] = payload | 0x80;
    }
  
    // Mask off the top bit of the last byte, to indicate the end of the
    // encoding.
    result[byteCount - 1] &= 0x7f;
    return result;
  }
docs: Common encoder for both signed and unsigned ints. This takes a
  bigint-ish buffer, returning an LEB128-encoded buffer.