@dfinity/candid
Advanced tools
Comparing version 0.11.3 to 0.12.0
@@ -138,2 +138,18 @@ "use strict"; | ||
} | ||
visitFixedInt(t, v) { | ||
if (t._bits <= 32) { | ||
return parseInt(v, 10); | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitFixedNat(t, v) { | ||
if (t._bits <= 32) { | ||
return parseInt(v, 10); | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitNumber(t, v) { | ||
@@ -173,6 +189,18 @@ return BigInt(v); | ||
visitFixedInt(t, v) { | ||
return BigInt(this.generateNumber(true)); | ||
const x = this.generateNumber(true); | ||
if (t._bits <= 32) { | ||
return x; | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitFixedNat(t, v) { | ||
return BigInt(this.generateNumber(false)); | ||
const x = this.generateNumber(false); | ||
if (t._bits <= 32) { | ||
return x; | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
@@ -179,0 +207,0 @@ generateNumber(signed) { |
@@ -197,3 +197,3 @@ import { Principal as PrincipalId } from '@dfinity/principal'; | ||
export declare class FixedIntClass extends PrimitiveType<bigint | number> { | ||
_bits: number; | ||
readonly _bits: number; | ||
constructor(_bits: number); | ||
@@ -212,4 +212,4 @@ accept<D, R>(v: Visitor<D, R>, d: D): R; | ||
export declare class FixedNatClass extends PrimitiveType<bigint | number> { | ||
readonly bits: number; | ||
constructor(bits: number); | ||
readonly _bits: number; | ||
constructor(_bits: number); | ||
accept<D, R>(v: Visitor<D, R>, d: D): R; | ||
@@ -216,0 +216,0 @@ covariant(x: any): x is bigint; |
@@ -550,5 +550,5 @@ "use strict"; | ||
class FixedNatClass extends PrimitiveType { | ||
constructor(bits) { | ||
constructor(_bits) { | ||
super(); | ||
this.bits = bits; | ||
this._bits = _bits; | ||
} | ||
@@ -559,3 +559,3 @@ accept(v, d) { | ||
covariant(x) { | ||
const max = BigInt(2) ** BigInt(this.bits); | ||
const max = BigInt(2) ** BigInt(this._bits); | ||
if (typeof x === 'bigint' && x >= BigInt(0)) { | ||
@@ -573,6 +573,6 @@ return x < max; | ||
encodeValue(x) { | ||
return (0, leb128_1.writeUIntLE)(x, this.bits / 8); | ||
return (0, leb128_1.writeUIntLE)(x, this._bits / 8); | ||
} | ||
encodeType() { | ||
const offset = Math.log2(this.bits) - 3; | ||
const offset = Math.log2(this._bits) - 3; | ||
return (0, leb128_1.slebEncode)(-5 - offset); | ||
@@ -582,4 +582,4 @@ } | ||
this.checkType(t); | ||
const num = (0, leb128_1.readUIntLE)(b, this.bits / 8); | ||
if (this.bits <= 32) { | ||
const num = (0, leb128_1.readUIntLE)(b, this._bits / 8); | ||
if (this._bits <= 32) { | ||
return Number(num); | ||
@@ -592,3 +592,3 @@ } | ||
get name() { | ||
return `nat${this.bits}`; | ||
return `nat${this._bits}`; | ||
} | ||
@@ -619,3 +619,3 @@ valueToString(x) { | ||
this._blobOptimization = false; | ||
if (_type instanceof FixedNatClass && _type.bits === 8) { | ||
if (_type instanceof FixedNatClass && _type._bits === 8) { | ||
this._blobOptimization = true; | ||
@@ -629,5 +629,9 @@ } | ||
// Special case for ArrayBuffer | ||
const bits = this._type instanceof FixedNatClass ? this._type.bits : (this._type instanceof FixedIntClass ? this._type._bits : 0); | ||
return (ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) | ||
|| (Array.isArray(x) && x.every(v => this._type.covariant(v))); | ||
const bits = this._type instanceof FixedNatClass | ||
? this._type._bits | ||
: this._type instanceof FixedIntClass | ||
? this._type._bits | ||
: 0; | ||
return ((ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) || | ||
(Array.isArray(x) && x.every(v => this._type.covariant(v)))); | ||
} | ||
@@ -663,12 +667,12 @@ encodeValue(x) { | ||
if (this._type instanceof FixedNatClass) { | ||
if (this._type.bits == 8) { | ||
if (this._type._bits == 8) { | ||
return new Uint8Array(b.read(len)); | ||
} | ||
if (this._type.bits == 16) { | ||
if (this._type._bits == 16) { | ||
return new Uint16Array(b.read(len * 2)); | ||
} | ||
if (this._type.bits == 32) { | ||
if (this._type._bits == 32) { | ||
return new Uint32Array(b.read(len * 4)); | ||
} | ||
if (this._type.bits == 64) { | ||
if (this._type._bits == 64) { | ||
return new BigUint64Array(b.read(len * 8)); | ||
@@ -675,0 +679,0 @@ } |
@@ -109,2 +109,18 @@ import * as IDL from './idl'; | ||
} | ||
visitFixedInt(t, v) { | ||
if (t._bits <= 32) { | ||
return parseInt(v, 10); | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitFixedNat(t, v) { | ||
if (t._bits <= 32) { | ||
return parseInt(v, 10); | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitNumber(t, v) { | ||
@@ -144,6 +160,18 @@ return BigInt(v); | ||
visitFixedInt(t, v) { | ||
return BigInt(this.generateNumber(true)); | ||
const x = this.generateNumber(true); | ||
if (t._bits <= 32) { | ||
return x; | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
visitFixedNat(t, v) { | ||
return BigInt(this.generateNumber(false)); | ||
const x = this.generateNumber(false); | ||
if (t._bits <= 32) { | ||
return x; | ||
} | ||
else { | ||
return BigInt(v); | ||
} | ||
} | ||
@@ -150,0 +178,0 @@ generateNumber(signed) { |
@@ -197,3 +197,3 @@ import { Principal as PrincipalId } from '@dfinity/principal'; | ||
export declare class FixedIntClass extends PrimitiveType<bigint | number> { | ||
_bits: number; | ||
readonly _bits: number; | ||
constructor(_bits: number); | ||
@@ -212,4 +212,4 @@ accept<D, R>(v: Visitor<D, R>, d: D): R; | ||
export declare class FixedNatClass extends PrimitiveType<bigint | number> { | ||
readonly bits: number; | ||
constructor(bits: number); | ||
readonly _bits: number; | ||
constructor(_bits: number); | ||
accept<D, R>(v: Visitor<D, R>, d: D): R; | ||
@@ -216,0 +216,0 @@ covariant(x: any): x is bigint; |
@@ -532,5 +532,5 @@ // tslint:disable:max-classes-per-file | ||
export class FixedNatClass extends PrimitiveType { | ||
constructor(bits) { | ||
constructor(_bits) { | ||
super(); | ||
this.bits = bits; | ||
this._bits = _bits; | ||
} | ||
@@ -541,3 +541,3 @@ accept(v, d) { | ||
covariant(x) { | ||
const max = BigInt(2) ** BigInt(this.bits); | ||
const max = BigInt(2) ** BigInt(this._bits); | ||
if (typeof x === 'bigint' && x >= BigInt(0)) { | ||
@@ -555,6 +555,6 @@ return x < max; | ||
encodeValue(x) { | ||
return writeUIntLE(x, this.bits / 8); | ||
return writeUIntLE(x, this._bits / 8); | ||
} | ||
encodeType() { | ||
const offset = Math.log2(this.bits) - 3; | ||
const offset = Math.log2(this._bits) - 3; | ||
return slebEncode(-5 - offset); | ||
@@ -564,4 +564,4 @@ } | ||
this.checkType(t); | ||
const num = readUIntLE(b, this.bits / 8); | ||
if (this.bits <= 32) { | ||
const num = readUIntLE(b, this._bits / 8); | ||
if (this._bits <= 32) { | ||
return Number(num); | ||
@@ -574,3 +574,3 @@ } | ||
get name() { | ||
return `nat${this.bits}`; | ||
return `nat${this._bits}`; | ||
} | ||
@@ -600,3 +600,3 @@ valueToString(x) { | ||
this._blobOptimization = false; | ||
if (_type instanceof FixedNatClass && _type.bits === 8) { | ||
if (_type instanceof FixedNatClass && _type._bits === 8) { | ||
this._blobOptimization = true; | ||
@@ -610,5 +610,9 @@ } | ||
// Special case for ArrayBuffer | ||
const bits = this._type instanceof FixedNatClass ? this._type.bits : (this._type instanceof FixedIntClass ? this._type._bits : 0); | ||
return (ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) | ||
|| (Array.isArray(x) && x.every(v => this._type.covariant(v))); | ||
const bits = this._type instanceof FixedNatClass | ||
? this._type._bits | ||
: this._type instanceof FixedIntClass | ||
? this._type._bits | ||
: 0; | ||
return ((ArrayBuffer.isView(x) && bits == x.BYTES_PER_ELEMENT * 8) || | ||
(Array.isArray(x) && x.every(v => this._type.covariant(v)))); | ||
} | ||
@@ -644,12 +648,12 @@ encodeValue(x) { | ||
if (this._type instanceof FixedNatClass) { | ||
if (this._type.bits == 8) { | ||
if (this._type._bits == 8) { | ||
return new Uint8Array(b.read(len)); | ||
} | ||
if (this._type.bits == 16) { | ||
if (this._type._bits == 16) { | ||
return new Uint16Array(b.read(len * 2)); | ||
} | ||
if (this._type.bits == 32) { | ||
if (this._type._bits == 32) { | ||
return new Uint32Array(b.read(len * 4)); | ||
} | ||
if (this._type.bits == 64) { | ||
if (this._type._bits == 64) { | ||
return new BigUint64Array(b.read(len * 8)); | ||
@@ -656,0 +660,0 @@ } |
{ | ||
"name": "@dfinity/candid", | ||
"version": "0.11.3", | ||
"version": "0.12.0", | ||
"author": "DFINITY Stiftung <sdk@dfinity.org>", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
414780
6437