How to use the long.UZERO 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 interledgerjs / ilp-protocol-stream / src / stream.ts View on Github external
constructor (opts: StreamOpts) {
    // Half-opened streams are not supported, support may be added in the future.
    super({ allowHalfOpen: false })
    this.id = opts.id
    this.isServer = opts.isServer
    this.log = createLogger(`ilp-protocol-stream:${this.isServer ? 'Server' : 'Client'}:Stream:${this.id}`)
    this.log.info('new stream created')

    this._totalSent = Long.UZERO
    this._totalReceived = Long.UZERO
    this._sendMax = Long.UZERO
    this._receiveMax = Long.UZERO
    this._outgoingHeldAmount = Long.UZERO

    this._sentEnd = false
    this._remoteSentEnd = false
    this.closed = false
    this.holds = {}

    this._incomingData = new OffsetSorter()
    this._outgoingData = new DataQueue()
    // TODO we might want to merge this with the _outgoingData queue data structure
    this._outgoingDataToRetry = []
    this.outgoingOffset = 0
github interledgerjs / ilp-protocol-stream / src / connection.ts View on Github external
protected async loadAndSendPacket (): Promise {
    // Actually send on the next tick of the event loop in case multiple streams
    // have their limits raised at the same time
    await new Promise((resolve, reject) => setImmediate(resolve))

    this.log.trace('loadAndSendPacket')
    let amountToSend = Long.UZERO

    // TODO make sure the queued frames aren't too big
    const requestPacket = new Packet(this.getNextPacketSequence(), IlpPacketType.Prepare, undefined, this.queuedFrames)
    this.queuedFrames = []

    // This is usually handled by the first test packet, but when the exchange rate
    // is fixed it happens here instead.
    this.maybePushAccountFrames(requestPacket)

    // Send control frames
    // TODO only send the max amount when it changes
    for (let [_, stream] of this.streams) {
      if (stream.isOpen()) {
        requestPacket.frames.push(new StreamMaxMoneyFrame(stream.id, stream.receiveMax, stream.totalReceived))
        requestPacket.frames.push(new StreamMaxDataFrame(stream.id, stream._getIncomingOffsets().maxAcceptable))
      }
github interledgerjs / ilp-protocol-stream / src / util / long.ts View on Github external
export function multiplyDivide (a: Long, b: Long, c: Long): {
  quo: Long,
  rem: Long
} {
  let quo = Long.UZERO // quotient
  let rem = Long.UZERO // remainder
  let qn = b.divide(c)
  let rn = b.modulo(c)

  while (!a.isZero()) {
    let oldQuo = quo
    if (!a.and(Long.UONE).isZero()) {
      quo = quo.add(qn)
      rem = rem.add(rn)
      if (rem.greaterThanOrEqual(c)) {
        quo = quo.add(Long.UONE)
        rem = rem.subtract(c)
      }
    }

    // Overflow.
github Yomguithereal / talisman / src / phonetics / eudex.js View on Github external
const array = charArray(word);

  let entry = array.length > 0 ?
    ((array[0] | 32) - A) & 0xFF :
    0;

  let firstByte = 0;

  if (entry < LETTERS)
    firstByte = INJECTIVE_PHONES[entry];
  else if (entry >= 0xDF && entry < 0xFF)
    firstByte = INJECTIVE_PHONES_C1[entry - 0xDF];

  firstByte = new Long(firstByte);

  let res = Long.UZERO,
      n = 0,
      b = 1;

  while (n < 8 && b < array.length) {
    entry = ((array[b] | 32) - A) & 0xFF;

    if (entry <= Z) {
      let x;

      if (entry < LETTERS)
        x = PHONES[entry];
      else if (entry >= 0xDF && entry < 0xFF)
        x = PHONES_C1[entry - 0xDF];
      else
        continue;
github interledgerjs / ilp-protocol-stream / src / util / long.ts View on Github external
export function checkedSubtract (a: Long, b: Long): {
  difference: Long,
  underflow: boolean
} {
  const difference = a.subtract(b)
  const underflow = difference.greaterThan(a) && difference.greaterThan(b)
  return {
    difference: underflow ? Long.UZERO : difference,
    underflow
  }
}
github interledgerjs / ilp-protocol-stream / src / stream.ts View on Github external
_getAmountStreamCanReceive (): Long {
    if (this._receiveMax.lessThan(this._totalReceived)) {
      return Long.UZERO
    }
    return checkedSubtract(this._receiveMax, this._totalReceived).difference
  }
github interledgerjs / ilp-protocol-stream / src / stream.ts View on Github external
_getAmountAvailableToSend (): Long {
    if (this.closed) {
      return Long.UZERO
    }
    const amountAvailable = checkedSubtract(
      checkedSubtract(this._sendMax, this._totalSent).difference,
      this._outgoingHeldAmount
    ).difference
    return amountAvailable
  }
github interledgerjs / ilp-protocol-stream / src / connection.ts View on Github external
this.queuedFrames = []

    this.congestion = new CongestionController({
      maximumPacketAmount: opts.maximumPacketAmount === undefined
        ? undefined
        : Long.fromString(opts.maximumPacketAmount, true)
    })
    this.retryDelay = RETRY_DELAY_START

    this.remoteKnowsOurAccount = this.isServer
    this.remoteMaxStreamId = DEFAULT_MAX_REMOTE_STREAMS * 2

    this.remoteMaxOffset = this.maxBufferedData

    this._totalReceived = Long.UZERO
    this._totalSent = Long.UZERO
    this._totalDelivered = Long.UZERO
    this._lastPacketExchangeRate = Rational.UZERO
  }
github interledgerjs / ilp-protocol-stream / src / connection.ts View on Github external
this.closed = true
    this.queuedFrames = []

    this.congestion = new CongestionController({
      maximumPacketAmount: opts.maximumPacketAmount === undefined
        ? undefined
        : Long.fromString(opts.maximumPacketAmount, true)
    })
    this.retryDelay = RETRY_DELAY_START

    this.remoteKnowsOurAccount = this.isServer
    this.remoteMaxStreamId = DEFAULT_MAX_REMOTE_STREAMS * 2

    this.remoteMaxOffset = this.maxBufferedData

    this._totalReceived = Long.UZERO
    this._totalSent = Long.UZERO
    this._totalDelivered = Long.UZERO
    this._lastPacketExchangeRate = Rational.UZERO
  }
github cloudstateio / cloudstate / node-support / src / crdts / gcounter.js View on Github external
function GCounter() {
  let currentValue = Long.UZERO;
  let delta = Long.UZERO;

  /**
   * The value as a long.
   *
   * @name module:cloudstate.crdt.GCounter#longValue
   * @type {Long}
   * @readonly
   */
  Object.defineProperty(this, "longValue", {
    get: function () {
      return currentValue;
    }
  });

  /**