/** * Decode Int 64 * @param buffer {Buffer} * @param offset {Number} * @returns {{value: Number, length: Number}} */ function get64 (buffer, offset = 0) { return { value: Long.fromBytesLE(buffer.slice(offset)).toString(), length: 8 } }
/** * Encode Unsigned Int 64 * @param value * @returns {Buffer} */ function putU64 (value) { return Buffer.from(Long.fromNumber(value, true).toBytesLE()) }
signers.forEach(item => { let signerMsg = signer.create({ address: item.address, weight: long.fromValue(item.weight), }); signersList.push(signerMsg); });
public GetTerminationTime(): AwsLongOutcome { if (Long.NEG_ONE.compare(this.terminationTime) === 0) { return new AwsLongOutcome(new GameLiftError(GameLiftErrorType.TERMINATION_TIME_NOT_SET)) } return new AwsLongOutcome(this.terminationTime) }
function winTickToMs(num) { const l = Long.fromString(`${num}`); if (l.compare(0) === 0) return 0; return ( l .divide(10000) .subtract(windowsTickEpoch) .toString() * 1 ); }
function createLongStr(str) { const buf = Buffer.alloc(8); const l = Long.fromString(`${str}`); buf.writeInt32LE(l.getLowBits(), 0); buf.writeInt32LE(l.getHighBits(), 4); return buf; }
it('int escape', function (done) { const buf = 19925; assert.equal(shareConn.escape(buf), '19925'); const maxValue = Long.fromString('18446744073709551615', true); assert.equal(shareConn.escape(maxValue), '18446744073709551615'); shareConn .query(' SELECT ' + shareConn.escape(buf) + ' t') .then((rows) => { assert.deepEqual(rows, [{ t: buf }]); done(); }) .catch(done); });
it('decodes Integer64', function() { expect(types.decode('Integer64', new Buffer('8000000180000002', 'hex'))) .toEqual(Long.fromString('8000000180000002', false, 16)); });
typeThresholds.forEach(item => { let typeThresholdMsg = typeThreshold.create({ type: parseInt(item.type), threshold: long.fromValue(item.threshold), }); typeThresholdsList.push(typeThresholdMsg); });
it('should encode/decode uint 64', () => { const values = [Long.MAX_UNSIGNED_VALUE.toString(), '0', '10', '518'] values.forEach((value) => { const encoded = GdCom.putU64(value) const decoded = GdCom.getU64(encoded) expect(decoded.value).to.be.equal(value) }) })
/** * Encode Int 64 * @param value * @returns {Buffer} */ function put64 (value) { return Buffer.from(Long.fromString(value.toString()).toBytesLE()) }
it('encodes Unsigned64', function() { expect(types.encode('Unsigned64', Long.fromString('8000000180000002', true, 16)).toString('hex')) .toBe('8000000180000002'); });
/** * Decode Unsigned Int 64 * @param buffer {Buffer} * @param offset {Number} * @returns {{value: Number, length: Number}} */ function getU64 (buffer, offset = 0) { return { value: Long.fromBytesLE(buffer.slice(offset), true).toString(), length: 8 } }