How to use the long.fromString 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 michaelwittig / node-q / lib / c.js View on Github external
function wtimestamp(x) {
		if (x === null) {
			wlong(null);
		} else {
			// 86400000000000 * (x.getTime() / 86400000 - 10957)
			wlong(Long.fromNumber(Long.fromString("1000000", false, 10).multiply(Long.fromNumber(x.getTime())).subtract(Long.fromString("946684800000000000", false, 10))));
		}
	}
	function wmonth(x) {
github node-modules / node-biginteger / lib / BigInteger.js View on Github external
0x18754571, 0x247dbc80, 0x3547667b, 0x4c4b4000, 0x6b5a6e1d,
  0x6c20a40,  0x8d2d931,  0xb640000,  0xe8d4a51,  0x1269ae40,
  0x17179149, 0x1cb91000, 0x23744899, 0x2b73a840, 0x34e63b41,
  0x40000000, 0x4cfa3cc1, 0x5c13d840, 0x6d91b519, 0x39aa400
];

var LONG_MASK = 0xffffffff;
var MAX_CONSTANT = 16;

var longRadix = [null, null,
  Long.fromString('4000000000000000',16), Long.fromString('383d9170b85ff80b',16),
  Long.fromString('4000000000000000',16), Long.fromString('6765c793fa10079d',16),
  Long.fromString('41c21cb8e1000000',16), Long.fromString('3642798750226111',16),
  Long.fromString('1000000000000000',16), Long.fromString('12bf307ae81ffd59',16),
  Long.fromString( 'de0b6b3a7640000',16), Long.fromString('4d28cb56c33fa539',16),
  Long.fromString('1eca170c00000000',16), Long.fromString('780c7372621bd74d',16),
  Long.fromString('1e39a5057d810000',16), Long.fromString('5b27ac993df97701',16),
  Long.fromString('1000000000000000',16), Long.fromString('27b95e997e21d9f1',16),
  Long.fromString('5da0e1e53c5c8000',16), Long.fromString( 'b16a458ef403f19',16),
  Long.fromString('16bcc41e90000000',16), Long.fromString('2d04b7fdd9c0ef49',16),
  Long.fromString('5658597bcaa24000',16), Long.fromString( '6feb266931a75b7',16),
  Long.fromString( 'c29e98000000000',16), Long.fromString('14adf4b7320334b9',16),
  Long.fromString('226ed36478bfa000',16), Long.fromString('383d9170b85ff80b',16),
  Long.fromString('5a3c23e39c000000',16), Long.fromString( '4e900abb53e6b71',16),
  Long.fromString( '7600ec618141000',16), Long.fromString( 'aee5720ee830681',16),
  Long.fromString('1000000000000000',16), Long.fromString('172588ad4f5f0981',16),
  Long.fromString('211e44f7d02c1000',16), Long.fromString('2ee56725f06e5c71',16),
  Long.fromString('41c21cb8e1000000',16)
];

/* zero[i] is a string of i consecutive zeros. */
var zeros = Common.intArray(64);
github SpencerSharkey / node-pogo-signature / lib / Builder.js View on Github external
Builder.prototype.getUk25 = function() {
    // if forced uk25 was passed in option, use it
    // we suppose unsigned negative long is a string is passed
    if (this.forcedUk25) {
        if (Long.isLong(this.forcedUk25)) return this.forcedUk25;
        else return longjs.fromString(this.forcedUk25, false);
    }

    // note: 0.45 return 0.57 uk25 as old uk25 seems to be blocked
    if (this.version.startsWith('0.45')) return longjs.fromString('-816976800928766045', false);
    else if (this.version.startsWith('0.51')) return longjs.fromString('-8832040574896607694', false);
    else if (this.version.startsWith('0.53')) return longjs.fromString('-76506539888958491', false);
    else if (this.version.startsWith('0.55')) return longjs.fromString('-9156899491064153954', false);
    else if (this.version.startsWith('0.57')) return longjs.fromString('-816976800928766045', false);
    else if (this.version.startsWith('0.59')) return longjs.fromString('-3226782243204485589', false);
    else if (this.version.startsWith('0.61')) return longjs.fromString('1296456256998993698', false);
    else if (this.version.startsWith('0.63')) return longjs.fromString('5348175887752539474', false);
    else if (this.version.startsWith('0.67')) return longjs.fromString('5395925083854747393', false);
    else if (this.version.startsWith('0.69')) return longjs.fromString('5395925083854747393', false);
    else throw new Error('Unhandled config version: ' + this.version);
};
github RiseVision / rise-node / tests / unit / helpers / protobuf.spec.ts View on Github external
it('should decode transportSignatures as expected', () => {
        const obj = {
          signatures: [
            {
              signature: Buffer.from('82a05312e312e31321231323331323431323531353261736461646638054080a', 'hex'),
              transaction: Long.fromString('1233578365736487563874', true),
            },
            {
              signature: Buffer.from('31323431323531353261736461646638054080a82a05312e312e313212313233', 'hex'),
              transaction: Long.fromString('5438588365736487563874', true),
            },
          ],
        };
        const buf = Buffer.from('0a2d08e2e4f4d1befbaeabdf01122082a05312e312e31321231323331323431323531353261736461646638054080a0a2d08e2e4c8fcadf8d1c9d301122031323431323531353261736461646638054080a82a05312e312e313212313233', 'hex');
        const out = instance.decodeToObj(buf, 'transportSignatures', 'postSignatures');
        expect(out).to.be.deep.equal(obj);
      });
github xtuc / webassemblyjs / test / interpreter / kernel / exec / numeric-instructions.js View on Github external
{
      name: "i64.add",

      args: [
        { value: Long.fromString("1844674407370955161"), type: "i64" },
        { value: Long.fromString("1"), type: "i64" }
      ],

      code: [
        t.instruction("get_local", [t.numberLiteral(0)]),
        t.instruction("get_local", [t.numberLiteral(1)]),
        t.objectInstruction("add", "i64")
      ],

      resEqual: new i64(Long.fromString("1844674407370955162"))
    },

    {
      name: "i64.sub",

      args: [
        { value: Long.fromString("1844674407370955161"), type: "i64" },
        { value: Long.fromString("1"), type: "i64" }
      ],

      code: [
        t.instruction("get_local", [t.numberLiteral(0)]),
        t.instruction("get_local", [t.numberLiteral(1)]),
        t.objectInstruction("sub", "i64")
      ],
github sidorares / node-mysql2 / test / integration / connection / test-insert-bigint.js View on Github external
connection.query("INSERT INTO bigs SET title='test4'", (err, result) => {
        assert.strictEqual(
          Long.fromString('90071992547409925').compare(result.insertId),
          0
        );
        connection.query(
          {
            sql: 'select * from bigs',
            supportBigNumbers: true,
            bigNumberString: false
          },
          (err, result) => {
            assert.strictEqual(result[0].id, 123);
            assert.strictEqual(result[1].id, 124);
            assert.strictEqual(result[2].id, 123456789);
            assert.strictEqual(result[3].id, 123456790);
            assert.strictEqual(result[4].id, 9007199254740992);
            assert.strictEqual(result[5].id, '9007199254740993');
            assert.strictEqual(result[6].id, '90071992547409924');
github nlf / protobuf.js / index.js View on Github external
value = varint.zigzag(item);
                } else {
                    value = item;
                }

                position += varint.write(result, fields[key].tag << 3, position);
                position += varint.write(result, value, position);
                break;

            case 'int64':
            case 'uint64':
            case 'sint64':
                if (typeof item === 'number') {
                    value = long.fromNumber(item, fields[key].type === 'uint64');
                } else if (typeof item === 'string') {
                    value = long.fromString(item, fields[key].type === 'uint64');
                } else {
                    value = item;
                }

                if (fields[key].type === 'sint64') {
                    value = varint.zigzag64(value);
                }

                position += varint.write(result, fields[key].tag << 3, position);
                position += varint.write64(result, value, position);
                break;

            case 'fixed64':
            case 'sfixed64':
            case 'double':
                if (typeof item === 'number') {
github lordoffox / adata / js / src / adata / adata.js View on Github external
else if (v < 0x10000) { return 3; }
        else if (v < 0x1000000) { return 4; }
        else { return 5; }
      }
      else {
        if (v.compare(u6B) < 0) { return 6; }
        else if (v.compare(u7B) < 0) { return 7; }
        else if (v.compare(u8B) < 0) { return 8; }
        else { return 9; }
      }
    }
  };
    
  var i2B = Long.fromString('100', false, 16);
  var i3B = Long.fromString('10000', false, 16);
  var i4B = Long.fromString('1000000', false, 16);
  var i5B = Long.fromString('100000000', false, 16);
  var i6B = Long.fromString('10000000000', false, 16);
  var i7B = Long.fromString('1000000000000', false, 16);
  var i8B = Long.fromString('100000000000000', false, 16);
  var i9B = Long.fromString('8000000000000000', false, 16);
    
  adata.prototype.szof_i64 = function (v) {
    'use asm';
    var h = 0;
    var nb = 0;
    if (Long.isLong(v)) {
      if (v.isNegative()) {
        nb = 1;
        v = v.multiply(-1);
      }
github MatthieuLemoine / push-receiver / src / gcm / index.js View on Github external
);
  AndroidCheckinResponse = root.lookupType(
    'checkin_proto.AndroidCheckinResponse'
  );
  const payload = {
    userSerialNumber : 0,
    checkin          : {
      type        : 3,
      chromeBuild : {
        platform      : 2,
        chromeVersion : '63.0.3234.0',
        channel       : 1,
      },
    },
    version       : 3,
    id            : androidId ? Long.fromString(androidId) : undefined,
    securityToken : securityToken
      ? Long.fromString(securityToken, true)
      : undefined,
  };
  const errMsg = AndroidCheckinRequest.verify(payload);
  if (errMsg) throw Error(errMsg);
  const message = AndroidCheckinRequest.create(payload);
  return AndroidCheckinRequest.encode(message).finish();
}
github wallix / datapeps-sdk-js / src / ID.js View on Github external
function unclip(data) {
        if (data instanceof Uint8Array) {
            var high = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
            var low = (data[4] << 24) + (data[5] << 16) + (data[6] << 8) + data[7];
            return { id: new Long(low, high, true), data: data.slice(8) };
        }
        var i = data.indexOf(".");
        var strId = data.slice(0, i);
        var id = Long.fromString(strId, true);
        return { id: id, data: data.slice(i + 1) };
    }
    ID.unclip = unclip;