node-opcua-basic-types 2.97.0 → 2.98.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/array.d.ts +16 -16
- package/dist/array.js +44 -44
- package/dist/attributeIds.d.ts +34 -34
- package/dist/attributeIds.js +48 -48
- package/dist/boolean.d.ts +9 -9
- package/dist/boolean.js +33 -33
- package/dist/byte_string.d.ts +11 -11
- package/dist/byte_string.js +36 -36
- package/dist/data_type.d.ts +31 -31
- package/dist/data_type.js +35 -35
- package/dist/date_time.d.ts +6 -6
- package/dist/date_time.js +20 -20
- package/dist/floats.d.ts +16 -16
- package/dist/floats.js +80 -80
- package/dist/guid.d.ts +9 -9
- package/dist/guid.js +121 -121
- package/dist/index.d.ts +19 -19
- package/dist/index.js +33 -33
- package/dist/integers.d.ts +66 -66
- package/dist/integers.js +308 -308
- package/dist/locale_id.d.ts +9 -9
- package/dist/locale_id.js +18 -18
- package/dist/node_id.d.ts +9 -9
- package/dist/node_id.js +188 -188
- package/dist/round_to_float.d.ts +1 -1
- package/dist/round_to_float.js +26 -26
- package/dist/status_code.d.ts +4 -4
- package/dist/status_code.js +20 -20
- package/dist/string.d.ts +12 -12
- package/dist/string.js +30 -30
- package/dist/utils.d.ts +12 -12
- package/dist/utils.js +19 -19
- package/package.json +17 -13
- package/nyc.config.js +0 -16
package/dist/integers.js
CHANGED
|
@@ -1,309 +1,309 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.coerceUInt32 = exports.coerceInt16 = exports.coerceUInt16 = exports.coerceSByte = exports.coerceByte = exports.coerceUInt8 = exports.coerceInt8 = exports.decodeInt64 = exports.encodeInt64 = exports.isValidInt64 = exports.coerceInt64 = exports.randomInt64 = exports.coerceUInt64 = exports.constructInt64 = exports.decodeUInt64 = exports.encodeUInt64 = exports.randomUInt64 = exports.isValidUInt64 = exports.decodeByte = exports.encodeByte = exports.randomByte = exports.isValidByte = exports.decodeUInt8 = exports.encodeUInt8 = exports.randomUInt8 = exports.isValidUInt8 = exports.decodeSByte = exports.encodeSByte = exports.randomSByte = exports.isValidSByte = exports.decodeInt8 = exports.encodeInt8 = exports.randomInt8 = exports.isValidInt8 = exports.decodeUInt32 = exports.encodeUInt32 = exports.randomUInt32 = exports.isValidUInt32 = exports.decodeInt32 = exports.encodeInt32 = exports.randomInt32 = exports.isValidInt32 = exports.decodeInt16 = exports.encodeInt16 = exports.randomInt16 = exports.isValidInt16 = exports.decodeUInt16 = exports.encodeUInt16 = exports.randomUInt16 = exports.isValidUInt16 = void 0;
|
|
4
|
-
exports.coerceInt32 = void 0;
|
|
5
|
-
/***
|
|
6
|
-
* @module node-opcua-basic-types
|
|
7
|
-
*/
|
|
8
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
function isValidUInt16(value) {
|
|
11
|
-
if (!isFinite(value)) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return value >= 0 && value <= 0xffff;
|
|
15
|
-
}
|
|
16
|
-
exports.isValidUInt16 = isValidUInt16;
|
|
17
|
-
// ---------------------------------------
|
|
18
|
-
function randomUInt16() {
|
|
19
|
-
return (0, utils_1.getRandomInt)(0, 0xffff);
|
|
20
|
-
}
|
|
21
|
-
exports.randomUInt16 = randomUInt16;
|
|
22
|
-
function encodeUInt16(value, stream) {
|
|
23
|
-
stream.writeUInt16(value);
|
|
24
|
-
}
|
|
25
|
-
exports.encodeUInt16 = encodeUInt16;
|
|
26
|
-
function decodeUInt16(stream, value) {
|
|
27
|
-
return stream.readUInt16();
|
|
28
|
-
}
|
|
29
|
-
exports.decodeUInt16 = decodeUInt16;
|
|
30
|
-
function isValidInt16(value) {
|
|
31
|
-
if (!isFinite(value)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return value >= -0x8000 && value <= 0x7fff;
|
|
35
|
-
}
|
|
36
|
-
exports.isValidInt16 = isValidInt16;
|
|
37
|
-
function randomInt16() {
|
|
38
|
-
return (0, utils_1.getRandomInt)(-0x8000, 0x7fff);
|
|
39
|
-
}
|
|
40
|
-
exports.randomInt16 = randomInt16;
|
|
41
|
-
function encodeInt16(value, stream) {
|
|
42
|
-
(0, node_opcua_assert_1.assert)(isFinite(value));
|
|
43
|
-
stream.writeInt16(value);
|
|
44
|
-
}
|
|
45
|
-
exports.encodeInt16 = encodeInt16;
|
|
46
|
-
function decodeInt16(stream, value) {
|
|
47
|
-
return stream.readInt16();
|
|
48
|
-
}
|
|
49
|
-
exports.decodeInt16 = decodeInt16;
|
|
50
|
-
function isValidInt32(value) {
|
|
51
|
-
if (!isFinite(value)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
return value >= -0x80000000 && value <= 0x7fffffff;
|
|
55
|
-
}
|
|
56
|
-
exports.isValidInt32 = isValidInt32;
|
|
57
|
-
function randomInt32() {
|
|
58
|
-
return (0, utils_1.getRandomInt)(-0x80000000, 0x7fffffff);
|
|
59
|
-
}
|
|
60
|
-
exports.randomInt32 = randomInt32;
|
|
61
|
-
function encodeInt32(value, stream) {
|
|
62
|
-
(0, node_opcua_assert_1.assert)(isFinite(value));
|
|
63
|
-
stream.writeInteger(value);
|
|
64
|
-
}
|
|
65
|
-
exports.encodeInt32 = encodeInt32;
|
|
66
|
-
function decodeInt32(stream, value) {
|
|
67
|
-
return stream.readInteger();
|
|
68
|
-
}
|
|
69
|
-
exports.decodeInt32 = decodeInt32;
|
|
70
|
-
function isValidUInt32(value) {
|
|
71
|
-
if (!isFinite(value)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return value >= 0 && value <= 0xffffffff;
|
|
75
|
-
}
|
|
76
|
-
exports.isValidUInt32 = isValidUInt32;
|
|
77
|
-
function randomUInt32() {
|
|
78
|
-
return (0, utils_1.getRandomInt)(0, 0xffffffff);
|
|
79
|
-
}
|
|
80
|
-
exports.randomUInt32 = randomUInt32;
|
|
81
|
-
function encodeUInt32(value, stream) {
|
|
82
|
-
stream.writeUInt32(value);
|
|
83
|
-
}
|
|
84
|
-
exports.encodeUInt32 = encodeUInt32;
|
|
85
|
-
function decodeUInt32(stream, value) {
|
|
86
|
-
return stream.readUInt32();
|
|
87
|
-
}
|
|
88
|
-
exports.decodeUInt32 = decodeUInt32;
|
|
89
|
-
function isValidInt8(value) {
|
|
90
|
-
if (!isFinite(value)) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
return value >= -0x80 && value <= 0x7f;
|
|
94
|
-
}
|
|
95
|
-
exports.isValidInt8 = isValidInt8;
|
|
96
|
-
function randomInt8() {
|
|
97
|
-
return (0, utils_1.getRandomInt)(-0x7f, 0x7e);
|
|
98
|
-
}
|
|
99
|
-
exports.randomInt8 = randomInt8;
|
|
100
|
-
function encodeInt8(value, stream) {
|
|
101
|
-
(0, node_opcua_assert_1.assert)(isValidInt8(value));
|
|
102
|
-
stream.writeInt8(value);
|
|
103
|
-
}
|
|
104
|
-
exports.encodeInt8 = encodeInt8;
|
|
105
|
-
function decodeInt8(stream, value) {
|
|
106
|
-
return stream.readInt8();
|
|
107
|
-
}
|
|
108
|
-
exports.decodeInt8 = decodeInt8;
|
|
109
|
-
exports.isValidSByte = isValidInt8;
|
|
110
|
-
exports.randomSByte = randomInt8;
|
|
111
|
-
exports.encodeSByte = encodeInt8;
|
|
112
|
-
exports.decodeSByte = decodeInt8;
|
|
113
|
-
function isValidUInt8(value) {
|
|
114
|
-
if (!isFinite(value)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return value >= 0x00 && value <= 0xff;
|
|
118
|
-
}
|
|
119
|
-
exports.isValidUInt8 = isValidUInt8;
|
|
120
|
-
function randomUInt8() {
|
|
121
|
-
return (0, utils_1.getRandomInt)(0x00, 0xff);
|
|
122
|
-
}
|
|
123
|
-
exports.randomUInt8 = randomUInt8;
|
|
124
|
-
function encodeUInt8(value, stream) {
|
|
125
|
-
stream.writeUInt8(value);
|
|
126
|
-
}
|
|
127
|
-
exports.encodeUInt8 = encodeUInt8;
|
|
128
|
-
function decodeUInt8(stream, value) {
|
|
129
|
-
return stream.readUInt8();
|
|
130
|
-
}
|
|
131
|
-
exports.decodeUInt8 = decodeUInt8;
|
|
132
|
-
exports.isValidByte = isValidUInt8;
|
|
133
|
-
exports.randomByte = randomUInt8;
|
|
134
|
-
exports.encodeByte = encodeUInt8;
|
|
135
|
-
exports.decodeByte = decodeUInt8;
|
|
136
|
-
function isValidUInt64(value) {
|
|
137
|
-
return value instanceof Array && value.length === 2;
|
|
138
|
-
}
|
|
139
|
-
exports.isValidUInt64 = isValidUInt64;
|
|
140
|
-
function randomUInt64() {
|
|
141
|
-
return [(0, utils_1.getRandomInt)(0, 0xffffffff), (0, utils_1.getRandomInt)(0, 0xffffffff)];
|
|
142
|
-
}
|
|
143
|
-
exports.randomUInt64 = randomUInt64;
|
|
144
|
-
function encodeUInt64(value, stream) {
|
|
145
|
-
if (typeof value === "number") {
|
|
146
|
-
const arr = coerceUInt64(value);
|
|
147
|
-
stream.writeUInt32(arr[1]);
|
|
148
|
-
stream.writeUInt32(arr[0]);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
stream.writeUInt32(value[1]);
|
|
152
|
-
stream.writeUInt32(value[0]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.encodeUInt64 = encodeUInt64;
|
|
156
|
-
function decodeUInt64(stream, value) {
|
|
157
|
-
const low = stream.readUInt32();
|
|
158
|
-
const high = stream.readUInt32();
|
|
159
|
-
return constructInt64(high, low);
|
|
160
|
-
}
|
|
161
|
-
exports.decodeUInt64 = decodeUInt64;
|
|
162
|
-
function constructInt64(high, low) {
|
|
163
|
-
if (high === 0 && low < 0) {
|
|
164
|
-
high = 0xffffffff;
|
|
165
|
-
low = 0xffffffff + low + 1;
|
|
166
|
-
}
|
|
167
|
-
(0, node_opcua_assert_1.assert)(low >= 0 && low <= 0xffffffff);
|
|
168
|
-
(0, node_opcua_assert_1.assert)(high >= 0 && high <= 0xffffffff);
|
|
169
|
-
return [high, low];
|
|
170
|
-
}
|
|
171
|
-
exports.constructInt64 = constructInt64;
|
|
172
|
-
function coerceUInt64(value) {
|
|
173
|
-
let high;
|
|
174
|
-
let low;
|
|
175
|
-
let v;
|
|
176
|
-
if (value === null || value === undefined) {
|
|
177
|
-
return [0, 0];
|
|
178
|
-
}
|
|
179
|
-
if (value instanceof Array) {
|
|
180
|
-
(0, node_opcua_assert_1.assert)(typeof value[0] === "number");
|
|
181
|
-
(0, node_opcua_assert_1.assert)(typeof value[1] === "number");
|
|
182
|
-
return value;
|
|
183
|
-
}
|
|
184
|
-
if (typeof value === "string") {
|
|
185
|
-
v = value.split(",");
|
|
186
|
-
if (v.length === 1) {
|
|
187
|
-
// was a single string, good news ! BigInt can be used with nodejs >=12
|
|
188
|
-
let a = BigInt(value);
|
|
189
|
-
if (a < BigInt(0)) {
|
|
190
|
-
const mask = BigInt("0xFFFFFFFFFFFFFFFF");
|
|
191
|
-
a = (mask + a + BigInt(1)) & mask;
|
|
192
|
-
}
|
|
193
|
-
high = Number(a >> BigInt(32));
|
|
194
|
-
low = Number(a & BigInt(0xffffffff));
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
high = parseInt(v[0], 10);
|
|
198
|
-
low = parseInt(v[1], 10);
|
|
199
|
-
}
|
|
200
|
-
return constructInt64(high, low);
|
|
201
|
-
}
|
|
202
|
-
if (value > 0xffffffff) {
|
|
203
|
-
// beware : as per javascript, value is a double here !
|
|
204
|
-
// our conversion will suffer from some inaccuracy
|
|
205
|
-
high = Math.floor(value / 0x100000000);
|
|
206
|
-
low = value - high * 0x100000000;
|
|
207
|
-
return constructInt64(high, low);
|
|
208
|
-
}
|
|
209
|
-
return constructInt64(0, value);
|
|
210
|
-
}
|
|
211
|
-
exports.coerceUInt64 = coerceUInt64;
|
|
212
|
-
function randomInt64() {
|
|
213
|
-
// High, low
|
|
214
|
-
return [(0, utils_1.getRandomInt)(0, 0xffffffff), (0, utils_1.getRandomInt)(0, 0xffffffff)];
|
|
215
|
-
}
|
|
216
|
-
exports.randomInt64 = randomInt64;
|
|
217
|
-
exports.coerceInt64 = coerceUInt64;
|
|
218
|
-
exports.isValidInt64 = isValidUInt64;
|
|
219
|
-
exports.encodeInt64 = encodeUInt64;
|
|
220
|
-
exports.decodeInt64 = decodeUInt64;
|
|
221
|
-
function coerceInt8(value) {
|
|
222
|
-
if (value === null || value === undefined) {
|
|
223
|
-
return 0;
|
|
224
|
-
}
|
|
225
|
-
if (typeof value === "number") {
|
|
226
|
-
return value;
|
|
227
|
-
}
|
|
228
|
-
return parseInt(value, 10);
|
|
229
|
-
}
|
|
230
|
-
exports.coerceInt8 = coerceInt8;
|
|
231
|
-
function coerceUInt8(value) {
|
|
232
|
-
if (value === null || value === undefined) {
|
|
233
|
-
return 0;
|
|
234
|
-
}
|
|
235
|
-
if (typeof value === "number") {
|
|
236
|
-
return value;
|
|
237
|
-
}
|
|
238
|
-
return parseInt(value, 10);
|
|
239
|
-
}
|
|
240
|
-
exports.coerceUInt8 = coerceUInt8;
|
|
241
|
-
function coerceByte(value) {
|
|
242
|
-
if (value === null || value === undefined) {
|
|
243
|
-
return 0;
|
|
244
|
-
}
|
|
245
|
-
if (typeof value === "number") {
|
|
246
|
-
return value;
|
|
247
|
-
}
|
|
248
|
-
return parseInt(value, 10);
|
|
249
|
-
}
|
|
250
|
-
exports.coerceByte = coerceByte;
|
|
251
|
-
function coerceSByte(value) {
|
|
252
|
-
if (value === null || value === undefined) {
|
|
253
|
-
return 0;
|
|
254
|
-
}
|
|
255
|
-
if (typeof value === "number") {
|
|
256
|
-
return value;
|
|
257
|
-
}
|
|
258
|
-
return parseInt(value, 10);
|
|
259
|
-
}
|
|
260
|
-
exports.coerceSByte = coerceSByte;
|
|
261
|
-
function coerceUInt16(value) {
|
|
262
|
-
if (value === null || value === undefined) {
|
|
263
|
-
return 0;
|
|
264
|
-
}
|
|
265
|
-
if (typeof value === "number") {
|
|
266
|
-
return value;
|
|
267
|
-
}
|
|
268
|
-
return parseInt(value, 10);
|
|
269
|
-
}
|
|
270
|
-
exports.coerceUInt16 = coerceUInt16;
|
|
271
|
-
function coerceInt16(value) {
|
|
272
|
-
if (value === null || value === undefined) {
|
|
273
|
-
return 0;
|
|
274
|
-
}
|
|
275
|
-
if (typeof value === "number") {
|
|
276
|
-
return value;
|
|
277
|
-
}
|
|
278
|
-
return parseInt(value, 10);
|
|
279
|
-
}
|
|
280
|
-
exports.coerceInt16 = coerceInt16;
|
|
281
|
-
function coerceUInt32(value) {
|
|
282
|
-
if (value === null || value === undefined) {
|
|
283
|
-
return 0;
|
|
284
|
-
}
|
|
285
|
-
if (value && Object.prototype.hasOwnProperty.call(value, "value")) {
|
|
286
|
-
// xx assert(value.constructor.name === "EnumItem");
|
|
287
|
-
return coerceUInt32(value.value);
|
|
288
|
-
}
|
|
289
|
-
if (typeof value === "number") {
|
|
290
|
-
return value;
|
|
291
|
-
}
|
|
292
|
-
return parseInt(value, 10);
|
|
293
|
-
}
|
|
294
|
-
exports.coerceUInt32 = coerceUInt32;
|
|
295
|
-
function coerceInt32(value) {
|
|
296
|
-
if (value === null || value === undefined) {
|
|
297
|
-
return 0;
|
|
298
|
-
}
|
|
299
|
-
if (value instanceof Array) {
|
|
300
|
-
// Int64 as a [high,low]
|
|
301
|
-
return value[1] + value[0] * 0xffffffff;
|
|
302
|
-
}
|
|
303
|
-
if (typeof value === "number") {
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
306
|
-
return parseInt(value, 10);
|
|
307
|
-
}
|
|
308
|
-
exports.coerceInt32 = coerceInt32;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coerceUInt32 = exports.coerceInt16 = exports.coerceUInt16 = exports.coerceSByte = exports.coerceByte = exports.coerceUInt8 = exports.coerceInt8 = exports.decodeInt64 = exports.encodeInt64 = exports.isValidInt64 = exports.coerceInt64 = exports.randomInt64 = exports.coerceUInt64 = exports.constructInt64 = exports.decodeUInt64 = exports.encodeUInt64 = exports.randomUInt64 = exports.isValidUInt64 = exports.decodeByte = exports.encodeByte = exports.randomByte = exports.isValidByte = exports.decodeUInt8 = exports.encodeUInt8 = exports.randomUInt8 = exports.isValidUInt8 = exports.decodeSByte = exports.encodeSByte = exports.randomSByte = exports.isValidSByte = exports.decodeInt8 = exports.encodeInt8 = exports.randomInt8 = exports.isValidInt8 = exports.decodeUInt32 = exports.encodeUInt32 = exports.randomUInt32 = exports.isValidUInt32 = exports.decodeInt32 = exports.encodeInt32 = exports.randomInt32 = exports.isValidInt32 = exports.decodeInt16 = exports.encodeInt16 = exports.randomInt16 = exports.isValidInt16 = exports.decodeUInt16 = exports.encodeUInt16 = exports.randomUInt16 = exports.isValidUInt16 = void 0;
|
|
4
|
+
exports.coerceInt32 = void 0;
|
|
5
|
+
/***
|
|
6
|
+
* @module node-opcua-basic-types
|
|
7
|
+
*/
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
function isValidUInt16(value) {
|
|
11
|
+
if (!isFinite(value)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return value >= 0 && value <= 0xffff;
|
|
15
|
+
}
|
|
16
|
+
exports.isValidUInt16 = isValidUInt16;
|
|
17
|
+
// ---------------------------------------
|
|
18
|
+
function randomUInt16() {
|
|
19
|
+
return (0, utils_1.getRandomInt)(0, 0xffff);
|
|
20
|
+
}
|
|
21
|
+
exports.randomUInt16 = randomUInt16;
|
|
22
|
+
function encodeUInt16(value, stream) {
|
|
23
|
+
stream.writeUInt16(value);
|
|
24
|
+
}
|
|
25
|
+
exports.encodeUInt16 = encodeUInt16;
|
|
26
|
+
function decodeUInt16(stream, value) {
|
|
27
|
+
return stream.readUInt16();
|
|
28
|
+
}
|
|
29
|
+
exports.decodeUInt16 = decodeUInt16;
|
|
30
|
+
function isValidInt16(value) {
|
|
31
|
+
if (!isFinite(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return value >= -0x8000 && value <= 0x7fff;
|
|
35
|
+
}
|
|
36
|
+
exports.isValidInt16 = isValidInt16;
|
|
37
|
+
function randomInt16() {
|
|
38
|
+
return (0, utils_1.getRandomInt)(-0x8000, 0x7fff);
|
|
39
|
+
}
|
|
40
|
+
exports.randomInt16 = randomInt16;
|
|
41
|
+
function encodeInt16(value, stream) {
|
|
42
|
+
(0, node_opcua_assert_1.assert)(isFinite(value));
|
|
43
|
+
stream.writeInt16(value);
|
|
44
|
+
}
|
|
45
|
+
exports.encodeInt16 = encodeInt16;
|
|
46
|
+
function decodeInt16(stream, value) {
|
|
47
|
+
return stream.readInt16();
|
|
48
|
+
}
|
|
49
|
+
exports.decodeInt16 = decodeInt16;
|
|
50
|
+
function isValidInt32(value) {
|
|
51
|
+
if (!isFinite(value)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return value >= -0x80000000 && value <= 0x7fffffff;
|
|
55
|
+
}
|
|
56
|
+
exports.isValidInt32 = isValidInt32;
|
|
57
|
+
function randomInt32() {
|
|
58
|
+
return (0, utils_1.getRandomInt)(-0x80000000, 0x7fffffff);
|
|
59
|
+
}
|
|
60
|
+
exports.randomInt32 = randomInt32;
|
|
61
|
+
function encodeInt32(value, stream) {
|
|
62
|
+
(0, node_opcua_assert_1.assert)(isFinite(value));
|
|
63
|
+
stream.writeInteger(value);
|
|
64
|
+
}
|
|
65
|
+
exports.encodeInt32 = encodeInt32;
|
|
66
|
+
function decodeInt32(stream, value) {
|
|
67
|
+
return stream.readInteger();
|
|
68
|
+
}
|
|
69
|
+
exports.decodeInt32 = decodeInt32;
|
|
70
|
+
function isValidUInt32(value) {
|
|
71
|
+
if (!isFinite(value)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return value >= 0 && value <= 0xffffffff;
|
|
75
|
+
}
|
|
76
|
+
exports.isValidUInt32 = isValidUInt32;
|
|
77
|
+
function randomUInt32() {
|
|
78
|
+
return (0, utils_1.getRandomInt)(0, 0xffffffff);
|
|
79
|
+
}
|
|
80
|
+
exports.randomUInt32 = randomUInt32;
|
|
81
|
+
function encodeUInt32(value, stream) {
|
|
82
|
+
stream.writeUInt32(value);
|
|
83
|
+
}
|
|
84
|
+
exports.encodeUInt32 = encodeUInt32;
|
|
85
|
+
function decodeUInt32(stream, value) {
|
|
86
|
+
return stream.readUInt32();
|
|
87
|
+
}
|
|
88
|
+
exports.decodeUInt32 = decodeUInt32;
|
|
89
|
+
function isValidInt8(value) {
|
|
90
|
+
if (!isFinite(value)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return value >= -0x80 && value <= 0x7f;
|
|
94
|
+
}
|
|
95
|
+
exports.isValidInt8 = isValidInt8;
|
|
96
|
+
function randomInt8() {
|
|
97
|
+
return (0, utils_1.getRandomInt)(-0x7f, 0x7e);
|
|
98
|
+
}
|
|
99
|
+
exports.randomInt8 = randomInt8;
|
|
100
|
+
function encodeInt8(value, stream) {
|
|
101
|
+
(0, node_opcua_assert_1.assert)(isValidInt8(value));
|
|
102
|
+
stream.writeInt8(value);
|
|
103
|
+
}
|
|
104
|
+
exports.encodeInt8 = encodeInt8;
|
|
105
|
+
function decodeInt8(stream, value) {
|
|
106
|
+
return stream.readInt8();
|
|
107
|
+
}
|
|
108
|
+
exports.decodeInt8 = decodeInt8;
|
|
109
|
+
exports.isValidSByte = isValidInt8;
|
|
110
|
+
exports.randomSByte = randomInt8;
|
|
111
|
+
exports.encodeSByte = encodeInt8;
|
|
112
|
+
exports.decodeSByte = decodeInt8;
|
|
113
|
+
function isValidUInt8(value) {
|
|
114
|
+
if (!isFinite(value)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return value >= 0x00 && value <= 0xff;
|
|
118
|
+
}
|
|
119
|
+
exports.isValidUInt8 = isValidUInt8;
|
|
120
|
+
function randomUInt8() {
|
|
121
|
+
return (0, utils_1.getRandomInt)(0x00, 0xff);
|
|
122
|
+
}
|
|
123
|
+
exports.randomUInt8 = randomUInt8;
|
|
124
|
+
function encodeUInt8(value, stream) {
|
|
125
|
+
stream.writeUInt8(value);
|
|
126
|
+
}
|
|
127
|
+
exports.encodeUInt8 = encodeUInt8;
|
|
128
|
+
function decodeUInt8(stream, value) {
|
|
129
|
+
return stream.readUInt8();
|
|
130
|
+
}
|
|
131
|
+
exports.decodeUInt8 = decodeUInt8;
|
|
132
|
+
exports.isValidByte = isValidUInt8;
|
|
133
|
+
exports.randomByte = randomUInt8;
|
|
134
|
+
exports.encodeByte = encodeUInt8;
|
|
135
|
+
exports.decodeByte = decodeUInt8;
|
|
136
|
+
function isValidUInt64(value) {
|
|
137
|
+
return value instanceof Array && value.length === 2;
|
|
138
|
+
}
|
|
139
|
+
exports.isValidUInt64 = isValidUInt64;
|
|
140
|
+
function randomUInt64() {
|
|
141
|
+
return [(0, utils_1.getRandomInt)(0, 0xffffffff), (0, utils_1.getRandomInt)(0, 0xffffffff)];
|
|
142
|
+
}
|
|
143
|
+
exports.randomUInt64 = randomUInt64;
|
|
144
|
+
function encodeUInt64(value, stream) {
|
|
145
|
+
if (typeof value === "number") {
|
|
146
|
+
const arr = coerceUInt64(value);
|
|
147
|
+
stream.writeUInt32(arr[1]);
|
|
148
|
+
stream.writeUInt32(arr[0]);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
stream.writeUInt32(value[1]);
|
|
152
|
+
stream.writeUInt32(value[0]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.encodeUInt64 = encodeUInt64;
|
|
156
|
+
function decodeUInt64(stream, value) {
|
|
157
|
+
const low = stream.readUInt32();
|
|
158
|
+
const high = stream.readUInt32();
|
|
159
|
+
return constructInt64(high, low);
|
|
160
|
+
}
|
|
161
|
+
exports.decodeUInt64 = decodeUInt64;
|
|
162
|
+
function constructInt64(high, low) {
|
|
163
|
+
if (high === 0 && low < 0) {
|
|
164
|
+
high = 0xffffffff;
|
|
165
|
+
low = 0xffffffff + low + 1;
|
|
166
|
+
}
|
|
167
|
+
(0, node_opcua_assert_1.assert)(low >= 0 && low <= 0xffffffff);
|
|
168
|
+
(0, node_opcua_assert_1.assert)(high >= 0 && high <= 0xffffffff);
|
|
169
|
+
return [high, low];
|
|
170
|
+
}
|
|
171
|
+
exports.constructInt64 = constructInt64;
|
|
172
|
+
function coerceUInt64(value) {
|
|
173
|
+
let high;
|
|
174
|
+
let low;
|
|
175
|
+
let v;
|
|
176
|
+
if (value === null || value === undefined) {
|
|
177
|
+
return [0, 0];
|
|
178
|
+
}
|
|
179
|
+
if (value instanceof Array) {
|
|
180
|
+
(0, node_opcua_assert_1.assert)(typeof value[0] === "number");
|
|
181
|
+
(0, node_opcua_assert_1.assert)(typeof value[1] === "number");
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "string") {
|
|
185
|
+
v = value.split(",");
|
|
186
|
+
if (v.length === 1) {
|
|
187
|
+
// was a single string, good news ! BigInt can be used with nodejs >=12
|
|
188
|
+
let a = BigInt(value);
|
|
189
|
+
if (a < BigInt(0)) {
|
|
190
|
+
const mask = BigInt("0xFFFFFFFFFFFFFFFF");
|
|
191
|
+
a = (mask + a + BigInt(1)) & mask;
|
|
192
|
+
}
|
|
193
|
+
high = Number(a >> BigInt(32));
|
|
194
|
+
low = Number(a & BigInt(0xffffffff));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
high = parseInt(v[0], 10);
|
|
198
|
+
low = parseInt(v[1], 10);
|
|
199
|
+
}
|
|
200
|
+
return constructInt64(high, low);
|
|
201
|
+
}
|
|
202
|
+
if (value > 0xffffffff) {
|
|
203
|
+
// beware : as per javascript, value is a double here !
|
|
204
|
+
// our conversion will suffer from some inaccuracy
|
|
205
|
+
high = Math.floor(value / 0x100000000);
|
|
206
|
+
low = value - high * 0x100000000;
|
|
207
|
+
return constructInt64(high, low);
|
|
208
|
+
}
|
|
209
|
+
return constructInt64(0, value);
|
|
210
|
+
}
|
|
211
|
+
exports.coerceUInt64 = coerceUInt64;
|
|
212
|
+
function randomInt64() {
|
|
213
|
+
// High, low
|
|
214
|
+
return [(0, utils_1.getRandomInt)(0, 0xffffffff), (0, utils_1.getRandomInt)(0, 0xffffffff)];
|
|
215
|
+
}
|
|
216
|
+
exports.randomInt64 = randomInt64;
|
|
217
|
+
exports.coerceInt64 = coerceUInt64;
|
|
218
|
+
exports.isValidInt64 = isValidUInt64;
|
|
219
|
+
exports.encodeInt64 = encodeUInt64;
|
|
220
|
+
exports.decodeInt64 = decodeUInt64;
|
|
221
|
+
function coerceInt8(value) {
|
|
222
|
+
if (value === null || value === undefined) {
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
if (typeof value === "number") {
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
return parseInt(value, 10);
|
|
229
|
+
}
|
|
230
|
+
exports.coerceInt8 = coerceInt8;
|
|
231
|
+
function coerceUInt8(value) {
|
|
232
|
+
if (value === null || value === undefined) {
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
if (typeof value === "number") {
|
|
236
|
+
return value;
|
|
237
|
+
}
|
|
238
|
+
return parseInt(value, 10);
|
|
239
|
+
}
|
|
240
|
+
exports.coerceUInt8 = coerceUInt8;
|
|
241
|
+
function coerceByte(value) {
|
|
242
|
+
if (value === null || value === undefined) {
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
if (typeof value === "number") {
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
return parseInt(value, 10);
|
|
249
|
+
}
|
|
250
|
+
exports.coerceByte = coerceByte;
|
|
251
|
+
function coerceSByte(value) {
|
|
252
|
+
if (value === null || value === undefined) {
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
if (typeof value === "number") {
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
return parseInt(value, 10);
|
|
259
|
+
}
|
|
260
|
+
exports.coerceSByte = coerceSByte;
|
|
261
|
+
function coerceUInt16(value) {
|
|
262
|
+
if (value === null || value === undefined) {
|
|
263
|
+
return 0;
|
|
264
|
+
}
|
|
265
|
+
if (typeof value === "number") {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
return parseInt(value, 10);
|
|
269
|
+
}
|
|
270
|
+
exports.coerceUInt16 = coerceUInt16;
|
|
271
|
+
function coerceInt16(value) {
|
|
272
|
+
if (value === null || value === undefined) {
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
if (typeof value === "number") {
|
|
276
|
+
return value;
|
|
277
|
+
}
|
|
278
|
+
return parseInt(value, 10);
|
|
279
|
+
}
|
|
280
|
+
exports.coerceInt16 = coerceInt16;
|
|
281
|
+
function coerceUInt32(value) {
|
|
282
|
+
if (value === null || value === undefined) {
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
if (value && Object.prototype.hasOwnProperty.call(value, "value")) {
|
|
286
|
+
// xx assert(value.constructor.name === "EnumItem");
|
|
287
|
+
return coerceUInt32(value.value);
|
|
288
|
+
}
|
|
289
|
+
if (typeof value === "number") {
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
return parseInt(value, 10);
|
|
293
|
+
}
|
|
294
|
+
exports.coerceUInt32 = coerceUInt32;
|
|
295
|
+
function coerceInt32(value) {
|
|
296
|
+
if (value === null || value === undefined) {
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
if (value instanceof Array) {
|
|
300
|
+
// Int64 as a [high,low]
|
|
301
|
+
return value[1] + value[0] * 0xffffffff;
|
|
302
|
+
}
|
|
303
|
+
if (typeof value === "number") {
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
return parseInt(value, 10);
|
|
307
|
+
}
|
|
308
|
+
exports.coerceInt32 = coerceInt32;
|
|
309
309
|
//# sourceMappingURL=integers.js.map
|
package/dist/locale_id.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/***
|
|
2
|
-
* @module node-opcua-basic-types
|
|
3
|
-
*/
|
|
4
|
-
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
|
|
5
|
-
import { UAString } from "./string";
|
|
6
|
-
export declare function validateLocaleId(value: unknown): boolean;
|
|
7
|
-
export type LocaleId = UAString;
|
|
8
|
-
export declare function encodeLocaleId(localeId: LocaleId, stream: OutputBinaryStream): void;
|
|
9
|
-
export declare function decodeLocaleId(stream: BinaryStream): LocaleId;
|
|
1
|
+
/***
|
|
2
|
+
* @module node-opcua-basic-types
|
|
3
|
+
*/
|
|
4
|
+
import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
|
|
5
|
+
import { UAString } from "./string";
|
|
6
|
+
export declare function validateLocaleId(value: unknown): boolean;
|
|
7
|
+
export type LocaleId = UAString;
|
|
8
|
+
export declare function encodeLocaleId(localeId: LocaleId, stream: OutputBinaryStream): void;
|
|
9
|
+
export declare function decodeLocaleId(stream: BinaryStream): LocaleId;
|
package/dist/locale_id.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeLocaleId = exports.encodeLocaleId = exports.validateLocaleId = void 0;
|
|
4
|
-
const string_1 = require("./string");
|
|
5
|
-
function validateLocaleId(value) {
|
|
6
|
-
// TODO : check that localeID is well-formed
|
|
7
|
-
// see part 3 $8.4 page 63
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
exports.validateLocaleId = validateLocaleId;
|
|
11
|
-
function encodeLocaleId(localeId, stream) {
|
|
12
|
-
return (0, string_1.encodeUAString)(localeId, stream);
|
|
13
|
-
}
|
|
14
|
-
exports.encodeLocaleId = encodeLocaleId;
|
|
15
|
-
function decodeLocaleId(stream) {
|
|
16
|
-
return (0, string_1.decodeUAString)(stream);
|
|
17
|
-
}
|
|
18
|
-
exports.decodeLocaleId = decodeLocaleId;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeLocaleId = exports.encodeLocaleId = exports.validateLocaleId = void 0;
|
|
4
|
+
const string_1 = require("./string");
|
|
5
|
+
function validateLocaleId(value) {
|
|
6
|
+
// TODO : check that localeID is well-formed
|
|
7
|
+
// see part 3 $8.4 page 63
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
exports.validateLocaleId = validateLocaleId;
|
|
11
|
+
function encodeLocaleId(localeId, stream) {
|
|
12
|
+
return (0, string_1.encodeUAString)(localeId, stream);
|
|
13
|
+
}
|
|
14
|
+
exports.encodeLocaleId = encodeLocaleId;
|
|
15
|
+
function decodeLocaleId(stream) {
|
|
16
|
+
return (0, string_1.decodeUAString)(stream);
|
|
17
|
+
}
|
|
18
|
+
exports.decodeLocaleId = decodeLocaleId;
|
|
19
19
|
//# sourceMappingURL=locale_id.js.map
|