本文整理汇总了TypeScript中long.fromString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromString函数的具体用法?TypeScript fromString怎么用?TypeScript fromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromString函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should decode transportPeers as expected', () => {
const obj = {
peers: [
{
ip: '127.0.0.1',
port: 5555,
state: 2,
os: 'linux',
version: '1.1.1',
broadhash: '123124125152asdadf',
height: 5,
clock: 86400,
updated: Long.fromString('10', true),
nonce: 'nonce1',
},
{
ip: '127.0.0.2',
port: 5535,
state: 3,
os: 'ubuntu',
version: '1.0.1',
broadhash: 'asdadf1342352352352',
height: 5,
clock: 865600,
updated: Long.fromString('12', true),
nonce: 'nonce2',
},
],
};
const buf = Buffer.from('0a420a093132372e302e302e3110b32b180222056c696e75782a05312e312e31321231323331323431323531353261736461646638054080a305480a52066e6f6e6365310a440a093132372e302e302e32109f2b180322067562756e74752a05312e302e31321361736461646631333432333532333532333532380540c0ea34480c52066e6f6e636532', 'hex');
const out = instance.decodeToObj(buf, 'transportPeers');
expect(out).to.be.deep.equal(obj);
});
示例2: it
it('should call encode passing an object with the property signatures, of buffers and BigNum', async () => {
result = await instance.signatures();
expect(protoBufStub.stubs.encode.called).true;
expect(protoBufStub.stubs.encode.firstCall.args)
.deep.eq([
{
signatures: [
{
signatures: [Buffer.from('01', 'hex'), Buffer.from('02', 'hex'), Buffer.from('03', 'hex')],
transaction: Long.fromString('100'),
},
{
signatures: [Buffer.from('04', 'hex'), Buffer.from('05', 'hex'), Buffer.from('06', 'hex')],
transaction: Long.fromString('102'),
},
],
},
'transportSignatures', 'getSignaturesResponse']);
});
示例3: it
it('converts IntegerValue', () => {
const examples = [
types.MIN_SAFE_INTEGER,
-100,
-1,
0,
1,
100,
types.MAX_SAFE_INTEGER
];
for (const example of examples) {
const obj = s.toValue(new fieldValue.IntegerValue(example));
expect(obj).to.deep.equal({ integerValue: '' + example });
const longVal = Long.fromString(example.toString(), false);
expectValue(obj, 'integerValue').to.deep.equal(
longVal,
'for integer ' + example
);
}
});
示例4:
'use strict'
// **Github:** https://github.com/fidm/quic
//
// **License:** MIT
// https://github.com/dcodeIO/long.js/pull/60
import Long from 'long'
// http://isthe.com/chongo/tech/comp/fnv/#FNV-param
const fnvOffset64 = Long.fromString('14695981039346656037', true, 10)
const fnvPrime64 = Long.fromString('1099511628211', true, 10)
export function fnv1a64Hash (data: Buffer, le: boolean): Buffer {
let hash = Long.fromBits(fnvOffset64.getLowBits(), fnvOffset64.getHighBits(), true)
for (const bit of data) {
hash = hash.xor(bit)
hash = hash.mul(fnvPrime64)
}
return Buffer.from(hash.toBytes(le))
}
export class SecureContext {
}
export class SourceToken {
}
示例5: steamID_64_ToAccountID
export function steamID_64_ToAccountID(steamID64: string) {
let steamID_64_Identifier = long.fromString("0110000100000000", true, 16);
let longValue = long.fromValue(steamID64).subtract(steamID_64_Identifier);
return longValue.toString();
}