How to use the long.fromInt function in long

To help you get started, weā€™ve selected a few long examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-modules / node-biginteger / lib / MutableBigInteger.js View on Github external
MutableBigInteger.prototype.add = function (addend) {
    var x = this.intLen;
    var y = addend.intLen;
    var resultLen = (this.intLen > addend.intLen ? this.intLen : addend.intLen);
    var result = (this.value.length < resultLen ? Common.intArray(resultLen) : this.value);

    var rstart = result.length-1;
    var sum;
    var carry = Long.fromInt(0);

    // Add common parts of both numbers
    while(x>0 && y>0) {
        x--; y--;
        sum = Long.fromNumber(this.value[x+this.offset] >>> 32).add(
            Long.fromNumber(addend.value[y+addend.offset] >>> 32)
        ).add(carry);

        result[rstart--] = sum.low;
        carry = sum.shiftRightUnsigned(32);
    }

    // Add remainder of the longer number
    while(x>0) {
        x--;
        if (carry == 0 && result == this.value && rstart == (x + this.offset))
github datastax / nodejs-driver / lib / types / duration.js View on Github external
function readUnsignedVInt(input, offset) {
    const firstByte = input[offset.value++];
    if ((firstByte & 0x80) === 0) {
      return Long.fromInt(firstByte);
    }
    const sByteInt = fromSignedByteToInt(firstByte);
    const size = numberOfExtraBytesToRead(sByteInt);
    let result = Long.fromInt(sByteInt & firstByteValueMask(size));
    for (let ii = 0; ii < size; ii++) {
      const b = Long.fromInt(input[offset.value++]);
      //       (result << 8) | b
      result = result.shiftLeft(8).or(b);
    }
    return result;
  }
github hyperledger / fabric-sdk-node / fabric-network / src / impl / event / abstracteventlistener.js View on Github external
}
			if ((this.clientOptions.startBlock !== null) && (this.clientOptions.startBlock !== undefined) &&
				(this.clientOptions.endBlock !== null) && (this.clientOptions.endBlock !== undefined)) {
				logger.debug('startBlock and endBlock were given. Disabling event replay');
				this.options.replay = false;
			}
		}

		let checkpoint;
		if (this.useEventReplay() && this.checkpointer instanceof BaseCheckpointer) {
			this._firstCheckpoint = checkpoint = await this.checkpointer.loadLatestCheckpoint();
			const blockchainInfo = await this.channel.queryInfo();
			// eslint-disable-next-line no-prototype-builtins
			if (checkpoint && checkpoint.hasOwnProperty('blockNumber') && !isNaN(checkpoint.blockNumber) && blockchainInfo.height - 1 > Number(checkpoint.blockNumber)) {
				logger.debug(`Requested Block Number: ${Number(checkpoint.blockNumber) + 1} Latest Block Number: ${blockchainInfo.height - 1}`);
				this.clientOptions.startBlock = Long.fromInt(Number(checkpoint.blockNumber) + 1);
			}
		}
	}
github cockroachdb / cockroach-gen / pkg / ui / cluster-ui / src / util / fixLong.ts View on Github external
export function FixLong(value: Long | number): Long {
  if ((value as any) === 0) {
    return Long.fromInt(0);
  }
  return value as Long;
}
github cockroachdb / cockroach-gen / pkg / ui / cluster-ui / src / transactionsPage / transactions.fixture.ts View on Github external
key_data: {
          query:
            "WITH deleted_sessions AS (DELETE FROM sqlliveness WHERE expiration < $1 RETURNING session_id) SELECT count(*) FROM deleted_sessions",
          app: "$ internal-delete-sessions",
          distSQL: false,
          failed: false,
          opt: true,
          implicit_txn: true,
          vec: false,
        },
        node_id: 5,
      },
      stats: {
        count: Long.fromInt(141),
        nodes: [Long.fromNumber(1), Long.fromNumber(2), Long.fromNumber(3)],
        first_attempt_count: Long.fromInt(141),
        max_retries: Long.fromInt(0),
        legacy_last_err: "",
        num_rows: { mean: 0, squared_diffs: 0 },
        parse_lat: { mean: 0, squared_diffs: 0 },
        plan_lat: {
          mean: 0.003381439716312056,
          squared_diffs: 0.08767511878473759,
        },
        run_lat: {
          mean: 0.018693638297872336,
          squared_diffs: 1.045614239546554,
        },
        service_lat: {
          mean: -9223372036.832695,
          squared_diffs: 1.5448581299024227,
        },
github cockroachdb / cockroach-gen / pkg / ui / cluster-ui / src / util / appStats / appStats.fixture.ts View on Github external
nanos: 541858988,
        },
      },
      bytes_read: {
        mean: 75.36000000000003,
        squared_diffs: 3407477.7600000002,
      },
      rows_read: {
        mean: 0.07999999999999999,
        squared_diffs: 3.8399999999999994,
      },
      last_exec_timestamp: {
        seconds: Long.fromInt(1599650292),
        nanos: 111613000,
      },
      nodes: [Long.fromInt(1), Long.fromInt(2)],
      exec_stats: {
        count: new Long(0),
        network_bytes: { mean: 0, squared_diffs: 0 },
        max_mem_usage: { mean: 0, squared_diffs: 0 },
        contention_time: { mean: 0, squared_diffs: 0 },
        network_messages: { mean: 0, squared_diffs: 0 },
        max_disk_usage: { mean: 0, squared_diffs: 0 },
      },
    },
    id: new Long(8717981371097536892),
  },
  {
    key: {
      key_data: {
        query:
          "UPDATE system.jobs SET claim_session_id = _ WHERE ((claim_session_id != $1) AND (status IN (_, _, __more3__))) AND (NOT crdb_internal.sql_liveness_is_alive(claim_session_id))",
github wireapp / wire-web-packages / packages / core / src / main / cryptography / MessageHashService.ts View on Github external
private getLocationBytes(content: LocationContent): Buffer {
    const latitudeApproximate = Math.round(content.latitude * 1000);
    const longitudeApproximate = Math.round(content.longitude * 1000);

    const latitudeLong = Long.fromInt(latitudeApproximate).toBytesBE();
    const longitudeLong = Long.fromInt(longitudeApproximate).toBytesBE();

    const latitudeBuffer = Buffer.from(latitudeLong);
    const longitudeBuffer = Buffer.from(longitudeLong);

    return Buffer.concat([latitudeBuffer, longitudeBuffer]);
  }
github cockroachdb / cockroach-gen / pkg / ui / src / views / reports / containers / network / latency / latency.fixtures.ts View on Github external
const nodeNoLocality1 = {
  desc: {
    node_id: 1,
  },
  activity: {
    "1": { incoming: 85125, outgoing: 204928, latency: Long.fromInt(843506) },
    "2": {
      incoming: 1641005,
      outgoing: 196537462,
      latency: Long.fromInt(12141),
    },
    "3": { incoming: 27851, outgoing: 15530093 },
    "4": {
      incoming: 4346803,
      outgoing: 180065134,
      latency: Long.fromInt(505076),
    },
  },
};
const nodeNoLocality2 = {
  desc: {
    node_id: 2,
  },
  activity: {
    "1": {
      incoming: 8408467,
      outgoing: 97930352,
      latency: Long.fromInt(1455817),
    },
    "2": {},
    "3": { incoming: 22800, outgoing: 13925347 },
    "4": {
github cockroachdb / cockroach-gen / pkg / ui / src / util / appStats.spec.ts View on Github external
count: Long.fromNumber(count),
    first_attempt_count: Long.fromNumber(first_attempt_count),
    max_retries: Long.fromNumber(max_retries),
    num_rows: randomStat(100),
    parse_lat: randomStat(),
    plan_lat: randomStat(),
    run_lat: randomStat(),
    service_lat: randomStat(),
    overhead_lat: randomStat(),
    bytes_read: randomStat(),
    rows_read: randomStat(),
    sensitive_info: sensitiveInfo || makeSensitiveInfo(null, null),
    exec_stats: randomExecStats(),
    sql_type: "DDL",
    last_exec_timestamp: {
      seconds: Long.fromInt(1599670292),
      nanos: 111613000,
    },
  };
}
github cockroachdb / cockroach-gen / pkg / ui / ccl / src / views / reports / containers / stores / encryption.tsx View on Github external
calculatePercentage(active: Long, total: Long): number {
    if (active.eq(total)) {
      return 100;
    }
    return Long.fromInt(100).mul(active).toNumber() / total.toNumber();
  }