node-opcua-basic-types 2.71.0 → 2.72.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/string.js CHANGED
@@ -1,31 +1,31 @@
1
- "use strict";
2
- /***
3
- * @module node-opcua-basic-types
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.encodeUAString = exports.decodeUAString = exports.encodeString = exports.decodeString = exports.randomString = exports.isValidString = void 0;
7
- const utils_1 = require("./utils");
8
- function isValidString(value) {
9
- return typeof value === "string";
10
- }
11
- exports.isValidString = isValidString;
12
- function randomString() {
13
- const nbCar = (0, utils_1.getRandomInt)(1, 20);
14
- const cars = [];
15
- for (let i = 0; i < nbCar; i++) {
16
- cars.push(String.fromCharCode(65 + (0, utils_1.getRandomInt)(0, 26)));
17
- }
18
- return cars.join("");
19
- }
20
- exports.randomString = randomString;
21
- function decodeString(stream, value) {
22
- return stream.readString();
23
- }
24
- exports.decodeString = decodeString;
25
- function encodeString(value, stream) {
26
- stream.writeString(value);
27
- }
28
- exports.encodeString = encodeString;
29
- exports.decodeUAString = decodeString;
30
- exports.encodeUAString = encodeString;
1
+ "use strict";
2
+ /***
3
+ * @module node-opcua-basic-types
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.encodeUAString = exports.decodeUAString = exports.encodeString = exports.decodeString = exports.randomString = exports.isValidString = void 0;
7
+ const utils_1 = require("./utils");
8
+ function isValidString(value) {
9
+ return typeof value === "string";
10
+ }
11
+ exports.isValidString = isValidString;
12
+ function randomString() {
13
+ const nbCar = (0, utils_1.getRandomInt)(1, 20);
14
+ const cars = [];
15
+ for (let i = 0; i < nbCar; i++) {
16
+ cars.push(String.fromCharCode(65 + (0, utils_1.getRandomInt)(0, 26)));
17
+ }
18
+ return cars.join("");
19
+ }
20
+ exports.randomString = randomString;
21
+ function decodeString(stream, value) {
22
+ return stream.readString();
23
+ }
24
+ exports.decodeString = decodeString;
25
+ function encodeString(value, stream) {
26
+ stream.writeString(value);
27
+ }
28
+ exports.encodeString = encodeString;
29
+ exports.decodeUAString = decodeString;
30
+ exports.encodeUAString = encodeString;
31
31
  //# sourceMappingURL=string.js.map
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- /**
5
- * return a random integer value in the range of min inclusive and max exclusive
6
- * @method getRandomInt
7
- * @param min
8
- * @param max
9
- * @return {*}
10
- * @private
11
- */
12
- export declare function getRandomInt(min: number, max: number): number;
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ /**
5
+ * return a random integer value in the range of min inclusive and max exclusive
6
+ * @method getRandomInt
7
+ * @param min
8
+ * @param max
9
+ * @return {*}
10
+ * @private
11
+ */
12
+ export declare function getRandomInt(min: number, max: number): number;
package/dist/utils.js CHANGED
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRandomInt = void 0;
4
- /***
5
- * @module node-opcua-basic-types
6
- */
7
- /**
8
- * return a random integer value in the range of min inclusive and max exclusive
9
- * @method getRandomInt
10
- * @param min
11
- * @param max
12
- * @return {*}
13
- * @private
14
- */
15
- function getRandomInt(min, max) {
16
- // note : Math.random() returns a random number between 0 (inclusive) and 1 (exclusive):
17
- return Math.floor(Math.random() * (max - min)) + min;
18
- }
19
- exports.getRandomInt = getRandomInt;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRandomInt = void 0;
4
+ /***
5
+ * @module node-opcua-basic-types
6
+ */
7
+ /**
8
+ * return a random integer value in the range of min inclusive and max exclusive
9
+ * @method getRandomInt
10
+ * @param min
11
+ * @param max
12
+ * @return {*}
13
+ * @private
14
+ */
15
+ function getRandomInt(min, max) {
16
+ // note : Math.random() returns a random number between 0 (inclusive) and 1 (exclusive):
17
+ return Math.floor(Math.random() * (max - min)) + min;
18
+ }
19
+ exports.getRandomInt = getRandomInt;
20
20
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-basic-types",
3
- "version": "2.71.0",
3
+ "version": "2.72.1",
4
4
  "description": "pure nodejs OPCUA SDK - module -basic-types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "internet of things"
43
43
  ],
44
44
  "homepage": "http://node-opcua.github.io/",
45
- "gitHead": "10f7cc1e1cd30dfef75adad9cb709a78401fabf3"
45
+ "gitHead": "ba98dd91a9eada9815268c66c98ca5391bc884e7"
46
46
  }
@@ -155,7 +155,7 @@ export function randomUInt64(): UInt64 {
155
155
  return [getRandomInt(0, 0xffffffff), getRandomInt(0, 0xffffffff)];
156
156
  }
157
157
 
158
- export function encodeUInt64(value: UInt64 | number, stream: OutputBinaryStream): void {
158
+ export function encodeUInt64(value: UInt64 | number, stream: OutputBinaryStream): void {
159
159
  if (typeof value === "number") {
160
160
  const arr = coerceUInt64(value);
161
161
  stream.writeUInt32(arr[1]);
@@ -173,6 +173,10 @@ export function decodeUInt64(stream: BinaryStream, value?: UInt64): UInt64 {
173
173
  }
174
174
 
175
175
  export function constructInt64(high: UInt32, low: UInt32): Int64 {
176
+ if (high === 0 && low < 0) {
177
+ high = 0xffffffff;
178
+ low = 0xffffffff + low + 1;
179
+ }
176
180
  assert(low >= 0 && low <= 0xffffffff);
177
181
  assert(high >= 0 && high <= 0xffffffff);
178
182
  return [high, low];
@@ -192,14 +196,24 @@ export function coerceUInt64(value: number | UInt64 | Int32 | string | null): UI
192
196
  }
193
197
  if (typeof value === "string") {
194
198
  v = value.split(",");
195
- high = parseInt(v[0], 10);
196
- low = parseInt(v[1], 10);
199
+ if (v.length === 1) {
200
+ // was a single string, good news ! BigInt can be used with nodejs >=12
201
+ let a = BigInt(value);
202
+ if (a < BigInt(0)) {
203
+ const mask = BigInt("0xFFFFFFFFFFFFFFFF");
204
+ a = (mask + a + BigInt(1)) & mask;
205
+ }
206
+ high = Number(a >> BigInt(32));
207
+ low = Number(a & BigInt(0xffffffff));
208
+ } else {
209
+ high = parseInt(v[0], 10);
210
+ low = parseInt(v[1], 10);
211
+ }
197
212
  return constructInt64(high, low);
198
213
  }
199
214
  if (value > 0xffffffff) {
200
215
  // beware : as per javascript, value is a double here !
201
216
  // our conversion will suffer from some inaccuracy
202
-
203
217
  high = Math.floor(value / 0x100000000);
204
218
  low = value - high * 0x100000000;
205
219
  return constructInt64(high, low);