node-opcua-status-code 2.64.1 → 2.69.0

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.
@@ -1,322 +1,322 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-status-code
4
- */
5
- // tslint:disable:no-bitwise
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.coerceStatusCode = exports.StatusCodes = exports.ModifiableStatusCode = exports.decodeStatusCode = exports.getStatusCodeFromCode = exports.encodeStatusCode = exports.ConstantStatusCode = exports.StatusCode = exports.extraStatusCodeBits = void 0;
8
- const node_opcua_assert_1 = require("node-opcua-assert");
9
- function warnLog(...args) {
10
- /* istanbul ignore next */
11
- // tslint:disable-next-line:no-console
12
- console.warn(...args);
13
- }
14
- /**
15
- * StatusCode Special bits
16
- */
17
- exports.extraStatusCodeBits = {
18
- /**
19
- * **StructureChanged** 15:15
20
- * Indicates that the structure of the associated data value has changed since the last
21
- * Notification.
22
- * - Clients should not process the data value unless they re-read the metadata.
23
- * - Servers shall set this bit if the DataTypeEncoding used for a Variable changes.
24
- * - Servers shall also set this bit if the EnumStrings Property of the DataType of the Variable changes.
25
- * - This bit is provided to warn Clients that parse complex data values that their parsing
26
- * routines could fail because the serialized form of the data value has changed.
27
- * - This bit has meaning only for StatusCodes returned as part of a data change Notification
28
- * or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
29
- */
30
- StructureChanged: 0x1 << 15,
31
- /**
32
- * **SemanticsChanged** 14:14 Semantics of the associated data value have changed. Clients should not process the data
33
- * value until they re-read the metadata associated with the Variable.
34
- * - Servers should set this bit if the metadata has changed in way that could cause application errors if the
35
- * - Client does not re-read the metadata. For example, a change to the engineering units
36
- * could create problems if the Client uses the value to perform calculations.
37
- * - Part 8 defines the conditions where a Server shall set this bit for a DA Variable.
38
- * - Other specifications may define additional conditions.
39
- * - A Server may define other conditions that cause this bit to be set. This bit has meaning only for StatusCodes returned as part of a data change Notification
40
- * or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
41
- */
42
- SemanticChanged: 0x1 << 14,
43
- // Reserved 12:13 Reserved for future use. Shall always be zero.
44
- /**
45
- * **InfoType** 10:11
46
- * The type of information contained in the info bits. These bits have the following meanings:
47
- *
48
- * | Meaning |value | description|
49
- * |-----------------------------------|------|----------------------------------------------------|
50
- * | NotUsed | 00 | The info bits are not used and shall be set to zero. |
51
- * | DataValue | 01 | The StatusCode and its info bits are associated with a data value returned from the Server. This flag is only used in combination with StatusCodes defined in Part 8. |
52
- * | Reserved |1X | Reserved for future use. The info bits shall be ignored.|
53
- */
54
- InfoTypeDataValue: 0x1 << 10,
55
- // InfoBits 0:9 Additional information bits that qualify the StatusCode.
56
- // The structure of these bits depends on the Info Type field.
57
- //
58
- // LimitBits 8:9 The limit bits associated with the data value. The limits bits have the
59
- // following meanings:
60
- // Limit Bits Description
61
- // None 00 The value is free to change.
62
- // Low 01 The value is at the lower limit for the data source.
63
- // High 10 The value is at the higher limit for the data source.
64
- // Constant 11 The value is constant and cannot change.
65
- LimitLow: 0x1 << 8,
66
- LimitHigh: 0x2 << 8,
67
- LimitConstant: 0x3 << 8,
68
- /**
69
- * **Overflow** 7:7
70
- * - This bit shall only be set if the MonitoredItem queue size is greater than 1.
71
- * - If this bit is set, not every detected change has been returned since the Server’s
72
- * queue buffer for the MonitoredItem reached its limit and had to purge out data.
73
- *
74
- */
75
- Overflow: 0x1 << 7,
76
- // Reserved 5:6 Reserved for future use. Shall always be zero.
77
- // HistorianBits 0:4 These bits are set only when reading historical data. They indicate where the data value
78
- // came from and provide information that affects how the Client uses the data value.
79
- // The historian bits have the following meaning:
80
- // Raw XXX00 A raw data value.
81
- // Calculated XXX01 A data value which was calculated.
82
- // Interpolated XXX10 A data value which was interpolated.
83
- // Reserved XXX11 Undefined.
84
- // Partial XX1XX A data value which was calculated with an incomplete interval.
85
- // Extra Data X1XXX A raw data value that hides other data at the same timestamp.
86
- // Multi Value 1XXXX Multiple values match the Aggregate criteria (i.e. multiple
87
- // minimum values at different timestamps within the same interval).
88
- // Part 11 describes how these bits are used in more detail.
89
- /** historical data contains a data value which was calculated. */
90
- HistorianCalculated: 0x1 << 0,
91
- /** historical data contains a data value which was interpolated. */
92
- HistorianInterpolated: 0x2 << 0,
93
- /** historical data contains a data value which was calculated with an incomplete interval. */
94
- HistorianPartial: 0x1 << 2,
95
- /** historical data contains a raw data value that hides other data at the same timestamp. */
96
- HistorianExtraData: 0x1 << 3,
97
- /** Multiple values match the Aggregate criteria (i.e. multiple minimum values at different timestamps within the same interval). */
98
- HistorianMultiValue: 0x1 << 4
99
- };
100
- /**
101
- * a particular StatusCode , with it's value , name and description
102
- */
103
- class StatusCode {
104
- /**
105
- * returns a status code that can be modified
106
- */
107
- static makeStatusCode(statusCode, optionalBits) {
108
- const _base = coerceStatusCode(statusCode);
109
- const tmp = new ModifiableStatusCode({ _base });
110
- if (optionalBits || typeof optionalBits === "number") {
111
- tmp.set(optionalBits);
112
- }
113
- return tmp;
114
- }
115
- valueOf() {
116
- return this.value;
117
- }
118
- toString() {
119
- return this.name + " (0x" + ("0000" + this.value.toString(16)).substr(-8) + ")";
120
- }
121
- checkBit(mask) {
122
- return (this.value & mask) === mask;
123
- }
124
- /** returns true if the overflow bit is set */
125
- get hasOverflowBit() {
126
- return this.checkBit(exports.extraStatusCodeBits.Overflow);
127
- }
128
- /** returns true if the semanticChange bit is set */
129
- get hasSemanticChangedBit() {
130
- return this.checkBit(exports.extraStatusCodeBits.SemanticChanged);
131
- }
132
- /** returns true if the structureChange bit is set */
133
- get hasStructureChangedBit() {
134
- return this.checkBit(exports.extraStatusCodeBits.StructureChanged);
135
- }
136
- isNot(other) {
137
- (0, node_opcua_assert_1.assert)(other instanceof StatusCode);
138
- return this.value !== other.value;
139
- }
140
- equals(other) {
141
- (0, node_opcua_assert_1.assert)(other instanceof StatusCode);
142
- return this.value === other.value;
143
- }
144
- toJSON() {
145
- return { value: this.value };
146
- }
147
- toJSONFull() {
148
- return { value: this.value, name: this.name, description: this.description };
149
- }
150
- }
151
- exports.StatusCode = StatusCode;
152
- Object.defineProperty(StatusCode.prototype, "value", { enumerable: true });
153
- Object.defineProperty(StatusCode.prototype, "description", { enumerable: true });
154
- Object.defineProperty(StatusCode.prototype, "name", { enumerable: true });
155
- // tslint:disable:max-classes-per-file
156
- class ConstantStatusCode extends StatusCode {
157
- /**
158
- *
159
- * @param options
160
- * @param options
161
- * @param options.value
162
- * @param options.description
163
- * @param options.name
164
- *
165
- */
166
- constructor(options) {
167
- super();
168
- this._value = options.value;
169
- this._description = options.description;
170
- this._name = options.name;
171
- }
172
- get value() {
173
- return this._value;
174
- }
175
- get name() {
176
- return this._name;
177
- }
178
- get description() {
179
- return this._description;
180
- }
181
- }
182
- exports.ConstantStatusCode = ConstantStatusCode;
183
- Object.defineProperty(ConstantStatusCode.prototype, "_value", { enumerable: false, writable: true });
184
- Object.defineProperty(ConstantStatusCode.prototype, "_description", { enumerable: false, writable: true });
185
- Object.defineProperty(ConstantStatusCode.prototype, "_name", { enumerable: false, writable: true });
186
- Object.defineProperty(ConstantStatusCode.prototype, "value", { enumerable: true });
187
- Object.defineProperty(ConstantStatusCode.prototype, "description", { enumerable: true });
188
- Object.defineProperty(ConstantStatusCode.prototype, "name", { enumerable: true });
189
- function encodeStatusCode(statusCode, stream) {
190
- stream.writeUInt32(statusCode.value);
191
- }
192
- exports.encodeStatusCode = encodeStatusCode;
193
- /** @internal construct status codes fast search indexes */
194
- const statusCodesReversedMap = {};
195
- /**
196
- * returns the StatusCode corresponding to the provided value, if any
197
- * @note: if code is not known , then StatusCodes.Bad will be returned
198
- * @param code
199
- */
200
- function getStatusCodeFromCode(code) {
201
- const codeWithoutInfoBits = (code & 0xffff0000) >>> 0;
202
- const infoBits = code & 0x0000ffff;
203
- let sc = statusCodesReversedMap[codeWithoutInfoBits];
204
- /* istanbul ignore if */
205
- if (!sc) {
206
- sc = _generated_status_codes_1.StatusCodes.Bad;
207
- // tslint:disable-next-line: no-console
208
- console.log("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
209
- warnLog("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
210
- }
211
- if (infoBits) {
212
- const tmp = new ModifiableStatusCode({ _base: sc });
213
- tmp.set(infoBits);
214
- sc = tmp;
215
- }
216
- return sc;
217
- }
218
- exports.getStatusCodeFromCode = getStatusCodeFromCode;
219
- function decodeStatusCode(stream, _value) {
220
- const code = stream.readUInt32();
221
- return getStatusCodeFromCode(code);
222
- }
223
- exports.decodeStatusCode = decodeStatusCode;
224
- class ModifiableStatusCode extends StatusCode {
225
- constructor(options) {
226
- super();
227
- this._base = options._base;
228
- this._extraBits = 0;
229
- if (this._base instanceof ModifiableStatusCode) {
230
- this._extraBits = this._base._extraBits;
231
- this._base = this._base._base;
232
- }
233
- }
234
- get value() {
235
- return this._base.value + this._extraBits;
236
- }
237
- get name() {
238
- return this._base.name + this._getExtraName();
239
- }
240
- get description() {
241
- return this._base.description;
242
- }
243
- set(bit) {
244
- if (typeof bit === "string") {
245
- const bitsArray = bit.split(" | ");
246
- if (bitsArray.length > 1) {
247
- for (const bitArray of bitsArray) {
248
- this.set(bitArray);
249
- }
250
- return;
251
- }
252
- const tmp = exports.extraStatusCodeBits[bit];
253
- /* istanbul ignore next */
254
- if (!tmp) {
255
- throw new Error("Invalid StatusCode Bit " + bit);
256
- }
257
- bit = tmp;
258
- }
259
- this._extraBits = this._extraBits | bit;
260
- }
261
- unset(bit) {
262
- if (typeof bit === "string") {
263
- const bitsArray = bit.split(" | ");
264
- if (bitsArray.length > 1) {
265
- for (const bitArray of bitsArray) {
266
- this.unset(bitArray);
267
- }
268
- return;
269
- }
270
- const tmp = exports.extraStatusCodeBits[bit];
271
- /* istanbul ignore next */
272
- if (!tmp) {
273
- throw new Error("Invalid StatusCode Bit " + bit);
274
- }
275
- bit = tmp;
276
- }
277
- this._extraBits = this._extraBits & (~bit >>> 0);
278
- }
279
- _getExtraName() {
280
- const str = [];
281
- for (const [key, value] of Object.entries(exports.extraStatusCodeBits)) {
282
- if ((this._extraBits & value) === value) {
283
- str.push(key);
284
- }
285
- }
286
- /* istanbul ignore next */
287
- if (str.length === 0) {
288
- return "";
289
- }
290
- return "#" + str.join("|");
291
- }
292
- }
293
- exports.ModifiableStatusCode = ModifiableStatusCode;
294
- // hide private properties
295
- Object.defineProperty(ModifiableStatusCode.prototype, "_base", { enumerable: false, writable: true });
296
- Object.defineProperty(ModifiableStatusCode.prototype, "_extraBits", { enumerable: false, writable: true });
297
- const _generated_status_codes_1 = require("./_generated_status_codes");
298
- var _generated_status_codes_2 = require("./_generated_status_codes");
299
- Object.defineProperty(exports, "StatusCodes", { enumerable: true, get: function () { return _generated_status_codes_2.StatusCodes; } });
300
- function coerceStatusCode(statusCode) {
301
- if (statusCode instanceof StatusCode) {
302
- return statusCode;
303
- }
304
- if (Object.prototype.hasOwnProperty.call(statusCode, "value")) {
305
- return getStatusCodeFromCode(statusCode.value);
306
- }
307
- if (typeof statusCode === "number") {
308
- return getStatusCodeFromCode(statusCode);
309
- }
310
- const _StatusCodes = _generated_status_codes_1.StatusCodes;
311
- if (!_StatusCodes[statusCode]) {
312
- throw new Error("Cannot find StatusCode " + statusCode);
313
- }
314
- return _StatusCodes[statusCode];
315
- }
316
- exports.coerceStatusCode = coerceStatusCode;
317
- for (const name of Object.keys(_generated_status_codes_1.StatusCodes)) {
318
- const code = _generated_status_codes_1.StatusCodes[name];
319
- statusCodesReversedMap[code.value.toString()] = code;
320
- }
321
- _generated_status_codes_1.StatusCodes.makeStatusCode = StatusCode.makeStatusCode;
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-status-code
4
+ */
5
+ // tslint:disable:no-bitwise
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.coerceStatusCode = exports.StatusCodes = exports.ModifiableStatusCode = exports.decodeStatusCode = exports.getStatusCodeFromCode = exports.encodeStatusCode = exports.ConstantStatusCode = exports.StatusCode = exports.extraStatusCodeBits = void 0;
8
+ const node_opcua_assert_1 = require("node-opcua-assert");
9
+ function warnLog(...args) {
10
+ /* istanbul ignore next */
11
+ // tslint:disable-next-line:no-console
12
+ console.warn(...args);
13
+ }
14
+ /**
15
+ * StatusCode Special bits
16
+ */
17
+ exports.extraStatusCodeBits = {
18
+ /**
19
+ * **StructureChanged** 15:15
20
+ * Indicates that the structure of the associated data value has changed since the last
21
+ * Notification.
22
+ * - Clients should not process the data value unless they re-read the metadata.
23
+ * - Servers shall set this bit if the DataTypeEncoding used for a Variable changes.
24
+ * - Servers shall also set this bit if the EnumStrings Property of the DataType of the Variable changes.
25
+ * - This bit is provided to warn Clients that parse complex data values that their parsing
26
+ * routines could fail because the serialized form of the data value has changed.
27
+ * - This bit has meaning only for StatusCodes returned as part of a data change Notification
28
+ * or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
29
+ */
30
+ StructureChanged: 0x1 << 15,
31
+ /**
32
+ * **SemanticsChanged** 14:14 Semantics of the associated data value have changed. Clients should not process the data
33
+ * value until they re-read the metadata associated with the Variable.
34
+ * - Servers should set this bit if the metadata has changed in way that could cause application errors if the
35
+ * - Client does not re-read the metadata. For example, a change to the engineering units
36
+ * could create problems if the Client uses the value to perform calculations.
37
+ * - Part 8 defines the conditions where a Server shall set this bit for a DA Variable.
38
+ * - Other specifications may define additional conditions.
39
+ * - A Server may define other conditions that cause this bit to be set. This bit has meaning only for StatusCodes returned as part of a data change Notification
40
+ * or the HistoryRead. StatusCodes used in other contexts shall always set this bit to zero.
41
+ */
42
+ SemanticChanged: 0x1 << 14,
43
+ // Reserved 12:13 Reserved for future use. Shall always be zero.
44
+ /**
45
+ * **InfoType** 10:11
46
+ * The type of information contained in the info bits. These bits have the following meanings:
47
+ *
48
+ * | Meaning |value | description|
49
+ * |-----------------------------------|------|----------------------------------------------------|
50
+ * | NotUsed | 00 | The info bits are not used and shall be set to zero. |
51
+ * | DataValue | 01 | The StatusCode and its info bits are associated with a data value returned from the Server. This flag is only used in combination with StatusCodes defined in Part 8. |
52
+ * | Reserved |1X | Reserved for future use. The info bits shall be ignored.|
53
+ */
54
+ InfoTypeDataValue: 0x1 << 10,
55
+ // InfoBits 0:9 Additional information bits that qualify the StatusCode.
56
+ // The structure of these bits depends on the Info Type field.
57
+ //
58
+ // LimitBits 8:9 The limit bits associated with the data value. The limits bits have the
59
+ // following meanings:
60
+ // Limit Bits Description
61
+ // None 00 The value is free to change.
62
+ // Low 01 The value is at the lower limit for the data source.
63
+ // High 10 The value is at the higher limit for the data source.
64
+ // Constant 11 The value is constant and cannot change.
65
+ LimitLow: 0x1 << 8,
66
+ LimitHigh: 0x2 << 8,
67
+ LimitConstant: 0x3 << 8,
68
+ /**
69
+ * **Overflow** 7:7
70
+ * - This bit shall only be set if the MonitoredItem queue size is greater than 1.
71
+ * - If this bit is set, not every detected change has been returned since the Server’s
72
+ * queue buffer for the MonitoredItem reached its limit and had to purge out data.
73
+ *
74
+ */
75
+ Overflow: 0x1 << 7,
76
+ // Reserved 5:6 Reserved for future use. Shall always be zero.
77
+ // HistorianBits 0:4 These bits are set only when reading historical data. They indicate where the data value
78
+ // came from and provide information that affects how the Client uses the data value.
79
+ // The historian bits have the following meaning:
80
+ // Raw XXX00 A raw data value.
81
+ // Calculated XXX01 A data value which was calculated.
82
+ // Interpolated XXX10 A data value which was interpolated.
83
+ // Reserved XXX11 Undefined.
84
+ // Partial XX1XX A data value which was calculated with an incomplete interval.
85
+ // Extra Data X1XXX A raw data value that hides other data at the same timestamp.
86
+ // Multi Value 1XXXX Multiple values match the Aggregate criteria (i.e. multiple
87
+ // minimum values at different timestamps within the same interval).
88
+ // Part 11 describes how these bits are used in more detail.
89
+ /** historical data contains a data value which was calculated. */
90
+ HistorianCalculated: 0x1 << 0,
91
+ /** historical data contains a data value which was interpolated. */
92
+ HistorianInterpolated: 0x2 << 0,
93
+ /** historical data contains a data value which was calculated with an incomplete interval. */
94
+ HistorianPartial: 0x1 << 2,
95
+ /** historical data contains a raw data value that hides other data at the same timestamp. */
96
+ HistorianExtraData: 0x1 << 3,
97
+ /** Multiple values match the Aggregate criteria (i.e. multiple minimum values at different timestamps within the same interval). */
98
+ HistorianMultiValue: 0x1 << 4
99
+ };
100
+ /**
101
+ * a particular StatusCode , with it's value , name and description
102
+ */
103
+ class StatusCode {
104
+ /**
105
+ * returns a status code that can be modified
106
+ */
107
+ static makeStatusCode(statusCode, optionalBits) {
108
+ const _base = coerceStatusCode(statusCode);
109
+ const tmp = new ModifiableStatusCode({ _base });
110
+ if (optionalBits || typeof optionalBits === "number") {
111
+ tmp.set(optionalBits);
112
+ }
113
+ return tmp;
114
+ }
115
+ valueOf() {
116
+ return this.value;
117
+ }
118
+ toString() {
119
+ return this.name + " (0x" + (this.value.toString(16)).padStart(8, "0") + ")";
120
+ }
121
+ checkBit(mask) {
122
+ return (this.value & mask) === mask;
123
+ }
124
+ /** returns true if the overflow bit is set */
125
+ get hasOverflowBit() {
126
+ return this.checkBit(exports.extraStatusCodeBits.Overflow);
127
+ }
128
+ /** returns true if the semanticChange bit is set */
129
+ get hasSemanticChangedBit() {
130
+ return this.checkBit(exports.extraStatusCodeBits.SemanticChanged);
131
+ }
132
+ /** returns true if the structureChange bit is set */
133
+ get hasStructureChangedBit() {
134
+ return this.checkBit(exports.extraStatusCodeBits.StructureChanged);
135
+ }
136
+ isNot(other) {
137
+ (0, node_opcua_assert_1.assert)(other instanceof StatusCode);
138
+ return this.value !== other.value;
139
+ }
140
+ equals(other) {
141
+ (0, node_opcua_assert_1.assert)(other instanceof StatusCode);
142
+ return this.value === other.value;
143
+ }
144
+ toJSON() {
145
+ return { value: this.value };
146
+ }
147
+ toJSONFull() {
148
+ return { value: this.value, name: this.name, description: this.description };
149
+ }
150
+ }
151
+ exports.StatusCode = StatusCode;
152
+ Object.defineProperty(StatusCode.prototype, "value", { enumerable: true });
153
+ Object.defineProperty(StatusCode.prototype, "description", { enumerable: true });
154
+ Object.defineProperty(StatusCode.prototype, "name", { enumerable: true });
155
+ // tslint:disable:max-classes-per-file
156
+ class ConstantStatusCode extends StatusCode {
157
+ /**
158
+ *
159
+ * @param options
160
+ * @param options
161
+ * @param options.value
162
+ * @param options.description
163
+ * @param options.name
164
+ *
165
+ */
166
+ constructor(options) {
167
+ super();
168
+ this._value = options.value;
169
+ this._description = options.description;
170
+ this._name = options.name;
171
+ }
172
+ get value() {
173
+ return this._value;
174
+ }
175
+ get name() {
176
+ return this._name;
177
+ }
178
+ get description() {
179
+ return this._description;
180
+ }
181
+ }
182
+ exports.ConstantStatusCode = ConstantStatusCode;
183
+ Object.defineProperty(ConstantStatusCode.prototype, "_value", { enumerable: false, writable: true });
184
+ Object.defineProperty(ConstantStatusCode.prototype, "_description", { enumerable: false, writable: true });
185
+ Object.defineProperty(ConstantStatusCode.prototype, "_name", { enumerable: false, writable: true });
186
+ Object.defineProperty(ConstantStatusCode.prototype, "value", { enumerable: true });
187
+ Object.defineProperty(ConstantStatusCode.prototype, "description", { enumerable: true });
188
+ Object.defineProperty(ConstantStatusCode.prototype, "name", { enumerable: true });
189
+ function encodeStatusCode(statusCode, stream) {
190
+ stream.writeUInt32(statusCode.value);
191
+ }
192
+ exports.encodeStatusCode = encodeStatusCode;
193
+ /** @internal construct status codes fast search indexes */
194
+ const statusCodesReversedMap = {};
195
+ /**
196
+ * returns the StatusCode corresponding to the provided value, if any
197
+ * @note: if code is not known , then StatusCodes.Bad will be returned
198
+ * @param code
199
+ */
200
+ function getStatusCodeFromCode(code) {
201
+ const codeWithoutInfoBits = (code & 0xffff0000) >>> 0;
202
+ const infoBits = code & 0x0000ffff;
203
+ let sc = statusCodesReversedMap[codeWithoutInfoBits];
204
+ /* istanbul ignore if */
205
+ if (!sc) {
206
+ sc = _generated_status_codes_1.StatusCodes.Bad;
207
+ // tslint:disable-next-line: no-console
208
+ console.log("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
209
+ warnLog("expecting a known StatusCode but got 0x" + codeWithoutInfoBits.toString(16), " code was 0x" + code.toString(16));
210
+ }
211
+ if (infoBits) {
212
+ const tmp = new ModifiableStatusCode({ _base: sc });
213
+ tmp.set(infoBits);
214
+ sc = tmp;
215
+ }
216
+ return sc;
217
+ }
218
+ exports.getStatusCodeFromCode = getStatusCodeFromCode;
219
+ function decodeStatusCode(stream, _value) {
220
+ const code = stream.readUInt32();
221
+ return getStatusCodeFromCode(code);
222
+ }
223
+ exports.decodeStatusCode = decodeStatusCode;
224
+ class ModifiableStatusCode extends StatusCode {
225
+ constructor(options) {
226
+ super();
227
+ this._base = options._base;
228
+ this._extraBits = 0;
229
+ if (this._base instanceof ModifiableStatusCode) {
230
+ this._extraBits = this._base._extraBits;
231
+ this._base = this._base._base;
232
+ }
233
+ }
234
+ get value() {
235
+ return this._base.value + this._extraBits;
236
+ }
237
+ get name() {
238
+ return this._base.name + this._getExtraName();
239
+ }
240
+ get description() {
241
+ return this._base.description;
242
+ }
243
+ set(bit) {
244
+ if (typeof bit === "string") {
245
+ const bitsArray = bit.split(" | ");
246
+ if (bitsArray.length > 1) {
247
+ for (const bitArray of bitsArray) {
248
+ this.set(bitArray);
249
+ }
250
+ return;
251
+ }
252
+ const tmp = exports.extraStatusCodeBits[bit];
253
+ /* istanbul ignore next */
254
+ if (!tmp) {
255
+ throw new Error("Invalid StatusCode Bit " + bit);
256
+ }
257
+ bit = tmp;
258
+ }
259
+ this._extraBits = this._extraBits | bit;
260
+ }
261
+ unset(bit) {
262
+ if (typeof bit === "string") {
263
+ const bitsArray = bit.split(" | ");
264
+ if (bitsArray.length > 1) {
265
+ for (const bitArray of bitsArray) {
266
+ this.unset(bitArray);
267
+ }
268
+ return;
269
+ }
270
+ const tmp = exports.extraStatusCodeBits[bit];
271
+ /* istanbul ignore next */
272
+ if (!tmp) {
273
+ throw new Error("Invalid StatusCode Bit " + bit);
274
+ }
275
+ bit = tmp;
276
+ }
277
+ this._extraBits = this._extraBits & (~bit >>> 0);
278
+ }
279
+ _getExtraName() {
280
+ const str = [];
281
+ for (const [key, value] of Object.entries(exports.extraStatusCodeBits)) {
282
+ if ((this._extraBits & value) === value) {
283
+ str.push(key);
284
+ }
285
+ }
286
+ /* istanbul ignore next */
287
+ if (str.length === 0) {
288
+ return "";
289
+ }
290
+ return "#" + str.join("|");
291
+ }
292
+ }
293
+ exports.ModifiableStatusCode = ModifiableStatusCode;
294
+ // hide private properties
295
+ Object.defineProperty(ModifiableStatusCode.prototype, "_base", { enumerable: false, writable: true });
296
+ Object.defineProperty(ModifiableStatusCode.prototype, "_extraBits", { enumerable: false, writable: true });
297
+ const _generated_status_codes_1 = require("./_generated_status_codes");
298
+ var _generated_status_codes_2 = require("./_generated_status_codes");
299
+ Object.defineProperty(exports, "StatusCodes", { enumerable: true, get: function () { return _generated_status_codes_2.StatusCodes; } });
300
+ function coerceStatusCode(statusCode) {
301
+ if (statusCode instanceof StatusCode) {
302
+ return statusCode;
303
+ }
304
+ if (Object.prototype.hasOwnProperty.call(statusCode, "value")) {
305
+ return getStatusCodeFromCode(statusCode.value);
306
+ }
307
+ if (typeof statusCode === "number") {
308
+ return getStatusCodeFromCode(statusCode);
309
+ }
310
+ const _StatusCodes = _generated_status_codes_1.StatusCodes;
311
+ if (!_StatusCodes[statusCode]) {
312
+ throw new Error("Cannot find StatusCode " + statusCode);
313
+ }
314
+ return _StatusCodes[statusCode];
315
+ }
316
+ exports.coerceStatusCode = coerceStatusCode;
317
+ for (const name of Object.keys(_generated_status_codes_1.StatusCodes)) {
318
+ const code = _generated_status_codes_1.StatusCodes[name];
319
+ statusCodesReversedMap[code.value.toString()] = code;
320
+ }
321
+ _generated_status_codes_1.StatusCodes.makeStatusCode = StatusCode.makeStatusCode;
322
322
  //# sourceMappingURL=opcua_status_code.js.map