Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.convertToLong = (value) => {
let result;
if (Long.isLong(value)) {
result = value; // already a long
} else if (typeof value !== 'undefined' && value !== null) {
result = Long.fromValue(value);
// Long will return a zero for invalid strings so make sure we did
// not get a real zero as the incoming value
if (result.equals(Long.ZERO)) {
if (Number.isInteger(value) || value === '0') {
// all good
} else {
// anything else must be a string that is not a valid number
throw new Error(util.format('value:%s is not a valid number ', value));
}
}
} else {
throw new Error('value parameter is missing');
}
return result;
};
function numberOfLeadingZeros(value) {
if (value.equals(Long.ZERO)) {
return 64;
}
let n = 1;
let x = value.getHighBits();
if (x === 0) {
n += 32;
x = value.getLowBits();
}
if (x >>> 16 === 0) {
n += 16;
x <<= 16;
}
if (x >>> 24 === 0) {
n += 8;
x <<= 8;
}
exports.longString = function (i, radix) {
if (radix < 2 || radix > 36)
radix = 10;
if (radix === 10)
return i.toString();
var buf = new Array(65);
var charPos = 64;
var negative = i.compare(Long.ZERO) < 0;
if (!negative) {
i = i.negate();
}
radix = Long.fromInt(radix);
var _radix = radix.negate();
while (i.compare(_radix) <= 0) {
var rem = i.subtract(i.div(radix).multiply(radix));
buf[charPos--] = Integer.digits[rem.negate().low];
i = i.div(radix);
}
buf[charPos] = Integer.digits[i.negate().low];
if (negative) {
buf[--charPos] = '-';
}
function multiplyToLen(x, xlen, y, ylen, z) {
var xstart = xlen - 1;
var ystart = ylen - 1;
if (z == null || z.length < (xlen+ ylen))
z = Common.intArray(xlen+ylen);
var carry = Long.ZERO;
for (var j = ystart, k = ystart + 1 + xstart; j >= 0; j--, k--) {
var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[xstart] >>> 32)).add(carry);
z[k] = product.low;
carry = product.shiftRightUnsigned(32);
}
z[xstart] = carry.low;
for (var i = xstart-1; i >= 0; i--) {
carry = Long.ZERO;
for (var j = ystart, k = ystart + 1 + i; j >= 0; j--, k--) {
var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[i] >>> 32)).add(Long.fromNumber(z[k] >>> 32)).add(carry);
z[k] = product.low;
carry = product.shiftRightUnsigned(32);
}
z[i] = carry.low;
}
serialized(): Uint8Array {
const content = this.content.serialized();
const authKeyId = new TLLong(Long.ZERO).serialized();
const messageId = this.messageId.serialized();
const length = new TLInt(content.length).serialized();
return concat(authKeyId, messageId, length, content);
}
constructor(endpoint, config, onSocketDisconnect) {
ArgumentChecker.notEmpty(endpoint, 'endpoints');
this._endpoint = endpoint;
this._parseEndpoint(endpoint);
this._config = config;
this._state = STATE.INITIAL;
this._socket = null;
this._requestId = Long.ZERO;
this._handshakeRequestId = null;
this._protocolVersion = null;
this._requests = new Map();
this._onSocketDisconnect = onSocketDisconnect;
this._error = null;
this._wasConnected = false;
this._buffer = null;
this._offset = 0;
}
this.increment = function (increment) {
if (Long.ZERO.comp(increment) === 1) {
throw new Error("Cannot decrement a GCounter");
}
currentValue = currentValue.add(increment);
delta = delta.add(increment);
return this;
};
*/
entityPath: string;
/**
* @property {string} replyTo The reply to Guid for the management client.
*/
replyTo: string = generate_uuid();
/**
* @property $management sender, receiver on the same session.
* @private
*/
private _mgmtReqResLink?: RequestResponseLink;
/**
* @property _lastPeekedSequenceNumber Provides the sequence number of the last peeked message.
* @private
*/
private _lastPeekedSequenceNumber: Long = Long.ZERO;
/**
* @constructor
* Instantiates the management client.
* @param {ClientEntityContext} context The client entity context.
* @param {ManagementClientOptions} [options] Options to be provided for creating the
* "$management" client.
*/
constructor(context: ClientEntityContext, options?: ManagementClientOptions) {
super(`${context.entityPath}/$management`, context, {
address: options && options.address ? options.address : Constants.management,
audience:
options && options.audience
? options.audience
: `${context.namespace.config.endpoint}${context.entityPath}/$management`
});
var xstart = xlen - 1;
var ystart = ylen - 1;
if (z == null || z.length < (xlen+ ylen))
z = Common.intArray(xlen+ylen);
var carry = Long.ZERO;
for (var j = ystart, k = ystart + 1 + xstart; j >= 0; j--, k--) {
var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[xstart] >>> 32)).add(carry);
z[k] = product.low;
carry = product.shiftRightUnsigned(32);
}
z[xstart] = carry.low;
for (var i = xstart-1; i >= 0; i--) {
carry = Long.ZERO;
for (var j = ystart, k = ystart + 1 + i; j >= 0; j--, k--) {
var product = Long.fromNumber(y[j] >>> 32).multiply(Long.fromNumber(x[i] >>> 32)).add(Long.fromNumber(z[k] >>> 32)).add(carry);
z[k] = product.low;
carry = product.shiftRightUnsigned(32);
}
z[i] = carry.low;
}
return z;
}
function PNCounter() {
let currentValue = Long.ZERO;
let delta = Long.ZERO;
/**
* The value as a long.
*
* @name module:cloudstate.crdt.PNCounter#longValue
* @type {Long}
* @readonly
*/
Object.defineProperty(this, "longValue", {
get: function () {
return currentValue;
}
});
/**