opcjs-client 0.1.5 → 0.1.8
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/index.cjs +45 -739
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -695
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var opcjsBase = require('opcjs-base');
|
|
4
4
|
|
|
5
5
|
// src/client.ts
|
|
6
6
|
var ServiceBase = class {
|
|
@@ -9,14 +9,14 @@ var ServiceBase = class {
|
|
|
9
9
|
this.secureChannel = secureChannel;
|
|
10
10
|
}
|
|
11
11
|
createRequestHeader() {
|
|
12
|
-
const requestHeader = new
|
|
12
|
+
const requestHeader = new opcjsBase.RequestHeader();
|
|
13
13
|
requestHeader.authenticationToken = this.authToken;
|
|
14
14
|
requestHeader.timestamp = /* @__PURE__ */ new Date();
|
|
15
15
|
requestHeader.requestHandle = 0;
|
|
16
16
|
requestHeader.returnDiagnostics = 0;
|
|
17
17
|
requestHeader.auditEntryId = "";
|
|
18
18
|
requestHeader.timeoutHint = 6e4;
|
|
19
|
-
requestHeader.additionalHeader =
|
|
19
|
+
requestHeader.additionalHeader = opcjsBase.ExtensionObject.newEmpty();
|
|
20
20
|
return requestHeader;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -29,15 +29,15 @@ var SessionService = class _SessionService extends ServiceBase {
|
|
|
29
29
|
}
|
|
30
30
|
async createSession() {
|
|
31
31
|
console.log("Creating session...");
|
|
32
|
-
const clientDescription = new
|
|
32
|
+
const clientDescription = new opcjsBase.ApplicationDescription();
|
|
33
33
|
clientDescription.applicationUri = this.configuration.applicationUri;
|
|
34
34
|
clientDescription.productUri = this.configuration.productUri;
|
|
35
|
-
clientDescription.applicationName = new
|
|
36
|
-
clientDescription.applicationType =
|
|
35
|
+
clientDescription.applicationName = new opcjsBase.LocalizedText(void 0, this.configuration.productName);
|
|
36
|
+
clientDescription.applicationType = opcjsBase.ApplicationTypeEnum.Client;
|
|
37
37
|
clientDescription.gatewayServerUri = "";
|
|
38
38
|
clientDescription.discoveryProfileUri = "";
|
|
39
39
|
clientDescription.discoveryUrls = new Array();
|
|
40
|
-
const request = new
|
|
40
|
+
const request = new opcjsBase.CreateSessionRequest();
|
|
41
41
|
request.requestHeader = this.createRequestHeader();
|
|
42
42
|
request.clientDescription = clientDescription;
|
|
43
43
|
request.serverUri = "";
|
|
@@ -49,7 +49,7 @@ var SessionService = class _SessionService extends ServiceBase {
|
|
|
49
49
|
request.maxResponseMessageSize = 0;
|
|
50
50
|
console.log("Sending CreateSessionRequest...");
|
|
51
51
|
const response = await this.secureChannel.issueServiceRequest(request);
|
|
52
|
-
if (!response || !(response instanceof
|
|
52
|
+
if (!response || !(response instanceof opcjsBase.CreateSessionResponse)) {
|
|
53
53
|
throw new Error("Invalid response type for CreateSessionRequest");
|
|
54
54
|
}
|
|
55
55
|
const castedResponse = response;
|
|
@@ -71,15 +71,15 @@ var SessionService = class _SessionService extends ServiceBase {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
async activateSession(identityToken) {
|
|
74
|
-
const signatureData = new
|
|
74
|
+
const signatureData = new opcjsBase.SignatureData();
|
|
75
75
|
signatureData.algorithm = this.secureChannel.getSecurityPolicy();
|
|
76
76
|
signatureData.signature = new Uint8Array(0);
|
|
77
|
-
const request = new
|
|
77
|
+
const request = new opcjsBase.ActivateSessionRequest();
|
|
78
78
|
request.requestHeader = this.createRequestHeader();
|
|
79
79
|
request.clientSignature = signatureData;
|
|
80
80
|
request.clientSoftwareCertificates = new Array();
|
|
81
81
|
request.localeIds = ["en-US"];
|
|
82
|
-
request.userIdentityToken =
|
|
82
|
+
request.userIdentityToken = opcjsBase.ExtensionObject.newBinary(identityToken);
|
|
83
83
|
request.userTokenSignature = signatureData;
|
|
84
84
|
console.log("Sending ActivateSessionRequest...");
|
|
85
85
|
await this.secureChannel.issueServiceRequest(request);
|
|
@@ -130,7 +130,7 @@ var Session = class {
|
|
|
130
130
|
throw new Error(`UserIdentityToken of type ${tokenType} not supported by server`);
|
|
131
131
|
}
|
|
132
132
|
token.policyId = tokenPolicy.policyId;
|
|
133
|
-
if (tokenType ===
|
|
133
|
+
if (tokenType === opcjsBase.UserTokenTypeEnum.IssuedToken) {
|
|
134
134
|
if (!tokenPolicy.issuerEndpointUrl) {
|
|
135
135
|
throw new Error("IssuerEndpointUrl not defined for IssuedToken");
|
|
136
136
|
}
|
|
@@ -159,7 +159,7 @@ var SessionHandler = class {
|
|
|
159
159
|
return session;
|
|
160
160
|
}
|
|
161
161
|
constructor(secureChannel, configuration) {
|
|
162
|
-
this.sessionServices = new SessionService(
|
|
162
|
+
this.sessionServices = new SessionService(opcjsBase.NodeId.newTwoByte(0), secureChannel, configuration);
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
|
|
@@ -170,17 +170,17 @@ var AttrIdValue = 13;
|
|
|
170
170
|
var AttributeService = class extends ServiceBase {
|
|
171
171
|
async ReadValue(nodeIds) {
|
|
172
172
|
const readValueIds = nodeIds.map((ni) => {
|
|
173
|
-
const readValueId = new
|
|
173
|
+
const readValueId = new opcjsBase.ReadValueId();
|
|
174
174
|
readValueId.nodeId = ni;
|
|
175
175
|
readValueId.attributeId = AttrIdValue;
|
|
176
176
|
readValueId.indexRange = "";
|
|
177
|
-
readValueId.dataEncoding = new
|
|
177
|
+
readValueId.dataEncoding = new opcjsBase.QualifiedName(0, "");
|
|
178
178
|
return readValueId;
|
|
179
179
|
});
|
|
180
|
-
const request = new
|
|
180
|
+
const request = new opcjsBase.ReadRequest();
|
|
181
181
|
request.requestHeader = this.createRequestHeader();
|
|
182
182
|
request.maxAge = 6e4;
|
|
183
|
-
request.timestampsToReturn =
|
|
183
|
+
request.timestampsToReturn = opcjsBase.TimestampsToReturnEnum.Source;
|
|
184
184
|
request.nodesToRead = readValueIds;
|
|
185
185
|
console.log("Sending ReadRequest...");
|
|
186
186
|
const response = await this.secureChannel.issueServiceRequest(request);
|
|
@@ -251,7 +251,7 @@ var SubscriptionHandler = class {
|
|
|
251
251
|
async publish(acknowledgeSequenceNumbers) {
|
|
252
252
|
const acknowledgements = [];
|
|
253
253
|
for (let i = 0; i < acknowledgeSequenceNumbers.length; i++) {
|
|
254
|
-
const acknowledgement = new
|
|
254
|
+
const acknowledgement = new opcjsBase.SubscriptionAcknowledgement();
|
|
255
255
|
acknowledgement.subscriptionId = this.entries[i].subscriptionId;
|
|
256
256
|
acknowledgement.sequenceNumber = acknowledgeSequenceNumbers[i];
|
|
257
257
|
acknowledgements.push(acknowledgement);
|
|
@@ -285,7 +285,7 @@ var SubscriptionHandler = class {
|
|
|
285
285
|
var SubscriptionService = class extends ServiceBase {
|
|
286
286
|
// https://reference.opcfoundation.org/Core/Part4/v105/docs/5.14.2
|
|
287
287
|
async createSubscription() {
|
|
288
|
-
const request = new
|
|
288
|
+
const request = new opcjsBase.CreateSubscriptionRequest();
|
|
289
289
|
request.requestHeader = this.createRequestHeader();
|
|
290
290
|
request.requestedPublishingInterval = 2e3;
|
|
291
291
|
request.requestedLifetimeCount = 36e4;
|
|
@@ -300,7 +300,7 @@ var SubscriptionService = class extends ServiceBase {
|
|
|
300
300
|
}
|
|
301
301
|
// https://reference.opcfoundation.org/Core/Part4/v105/docs/5.14.5
|
|
302
302
|
async publish(acknowledgements) {
|
|
303
|
-
const request = new
|
|
303
|
+
const request = new opcjsBase.PublishRequest();
|
|
304
304
|
request.requestHeader = this.createRequestHeader();
|
|
305
305
|
request.subscriptionAcknowledgements = acknowledgements;
|
|
306
306
|
console.log("Sending publish...");
|
|
@@ -315,26 +315,26 @@ var SubscriptionService = class extends ServiceBase {
|
|
|
315
315
|
var MonitoredItemService = class extends ServiceBase {
|
|
316
316
|
async createMonitoredItems(subscriptionId, ids) {
|
|
317
317
|
const items = ids.map((ni) => {
|
|
318
|
-
const readValueId = new
|
|
318
|
+
const readValueId = new opcjsBase.ReadValueId();
|
|
319
319
|
readValueId.nodeId = ni.id;
|
|
320
320
|
readValueId.attributeId = AttrIdValue;
|
|
321
321
|
readValueId.indexRange = "";
|
|
322
|
-
readValueId.dataEncoding = new
|
|
323
|
-
const monitoringParameters = new
|
|
322
|
+
readValueId.dataEncoding = new opcjsBase.QualifiedName(0, "");
|
|
323
|
+
const monitoringParameters = new opcjsBase.MonitoringParameters();
|
|
324
324
|
monitoringParameters.clientHandle = ni.handle;
|
|
325
325
|
monitoringParameters.samplingInterval = 1e3;
|
|
326
|
-
monitoringParameters.filter =
|
|
326
|
+
monitoringParameters.filter = opcjsBase.ExtensionObject.newEmpty();
|
|
327
327
|
monitoringParameters.queueSize = 100;
|
|
328
328
|
monitoringParameters.discardOldest = true;
|
|
329
|
-
const monitoredItemCreateRequest = new
|
|
329
|
+
const monitoredItemCreateRequest = new opcjsBase.MonitoredItemCreateRequest();
|
|
330
330
|
monitoredItemCreateRequest.itemToMonitor = readValueId;
|
|
331
331
|
monitoredItemCreateRequest.requestedParameters = monitoringParameters;
|
|
332
332
|
return monitoredItemCreateRequest;
|
|
333
333
|
});
|
|
334
|
-
const request = new
|
|
334
|
+
const request = new opcjsBase.CreateMonitoredItemsRequest();
|
|
335
335
|
request.requestHeader = this.createRequestHeader();
|
|
336
336
|
request.subscriptionId = subscriptionId;
|
|
337
|
-
request.timestampsToReturn =
|
|
337
|
+
request.timestampsToReturn = opcjsBase.TimestampsToReturnEnum.Source;
|
|
338
338
|
request.itemsToCreate = items;
|
|
339
339
|
console.log("Sending createMonitoredItems...");
|
|
340
340
|
await this.secureChannel.issueServiceRequest(request);
|
|
@@ -362,7 +362,7 @@ var Client = class {
|
|
|
362
362
|
return this.session;
|
|
363
363
|
}
|
|
364
364
|
async connect() {
|
|
365
|
-
const channel =
|
|
365
|
+
const channel = opcjsBase.ChannelFactory.createChannel(this.endpointUrl);
|
|
366
366
|
let connected = false;
|
|
367
367
|
while (!connected) {
|
|
368
368
|
console.log(`Connecting to OPC UA server at ${this.endpointUrl}...`);
|
|
@@ -373,7 +373,7 @@ var Client = class {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
console.log("Connected to OPC UA server.");
|
|
376
|
-
this.channel = new
|
|
376
|
+
this.channel = new opcjsBase.SecureChannel(channel, this.configuration);
|
|
377
377
|
await this.channel.openSecureChannelRequest();
|
|
378
378
|
const sessionHandler = new SessionHandler(this.channel, this.configuration);
|
|
379
379
|
this.session = await sessionHandler.createNewSession(this.identity);
|
|
@@ -397,715 +397,21 @@ var Client = class {
|
|
|
397
397
|
this.subscriptionHandler?.subscribe(ids, callback);
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
|
-
|
|
401
|
-
// ../base/src/codecs/codecError.ts
|
|
402
|
-
var CodecError = class _CodecError extends Error {
|
|
403
|
-
/**
|
|
404
|
-
* The encoding ID involved in the error (if applicable).
|
|
405
|
-
*/
|
|
406
|
-
encodingId;
|
|
407
|
-
/**
|
|
408
|
-
* The encoding format where the error occurred (Binary, Xml, Json).
|
|
409
|
-
*/
|
|
410
|
-
format;
|
|
411
|
-
/**
|
|
412
|
-
* Suggested action to resolve the error.
|
|
413
|
-
*/
|
|
414
|
-
suggestedAction;
|
|
415
|
-
/**
|
|
416
|
-
* The type name involved in the error (if applicable).
|
|
417
|
-
*/
|
|
418
|
-
typeName;
|
|
419
|
-
/**
|
|
420
|
-
* Original error that caused this codec error (if any).
|
|
421
|
-
*/
|
|
422
|
-
cause;
|
|
423
|
-
constructor(message, options) {
|
|
424
|
-
super(message);
|
|
425
|
-
this.name = "CodecError";
|
|
426
|
-
this.encodingId = options?.encodingId;
|
|
427
|
-
this.format = options?.format;
|
|
428
|
-
this.suggestedAction = options?.suggestedAction;
|
|
429
|
-
this.typeName = options?.typeName;
|
|
430
|
-
this.cause = options?.cause;
|
|
431
|
-
if (Error.captureStackTrace) {
|
|
432
|
-
Error.captureStackTrace(this, _CodecError);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Returns a detailed error message including all context.
|
|
437
|
-
*/
|
|
438
|
-
toString() {
|
|
439
|
-
let result = `${this.name}: ${this.message}`;
|
|
440
|
-
if (this.encodingId) {
|
|
441
|
-
result += `
|
|
442
|
-
Encoding ID: ${this.encodingId}`;
|
|
443
|
-
}
|
|
444
|
-
if (this.format) {
|
|
445
|
-
result += `
|
|
446
|
-
Format: ${this.format}`;
|
|
447
|
-
}
|
|
448
|
-
if (this.typeName) {
|
|
449
|
-
result += `
|
|
450
|
-
Type: ${this.typeName}`;
|
|
451
|
-
}
|
|
452
|
-
if (this.suggestedAction) {
|
|
453
|
-
result += `
|
|
454
|
-
Suggested Action: ${this.suggestedAction}`;
|
|
455
|
-
}
|
|
456
|
-
return result;
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// ../base/src/codecs/binary/binaryWriter.ts
|
|
461
|
-
var EPOCH_DIFF_MS = 11644473600000n;
|
|
462
|
-
var TICKS_PER_MS = 10000n;
|
|
463
|
-
function selectNodeIdEncodingFormat(nodeId) {
|
|
464
|
-
if (nodeId.identifierType === 0 /* Numeric */) {
|
|
465
|
-
const id = nodeId.identifier;
|
|
466
|
-
const ns = nodeId.namespace;
|
|
467
|
-
if (ns === 0 && id >= 0 && id <= 255) {
|
|
468
|
-
return 0 /* TwoByte */;
|
|
469
|
-
}
|
|
470
|
-
if (ns >= 0 && ns <= 255 && id >= 0 && id <= 65535) {
|
|
471
|
-
return 1 /* FourByte */;
|
|
472
|
-
}
|
|
473
|
-
return 2 /* Numeric */;
|
|
474
|
-
}
|
|
475
|
-
if (nodeId.identifierType === 1 /* String */) {
|
|
476
|
-
return 3 /* String */;
|
|
477
|
-
}
|
|
478
|
-
if (nodeId.identifierType === 2 /* Guid */) {
|
|
479
|
-
return 4 /* Guid */;
|
|
480
|
-
}
|
|
481
|
-
if (nodeId.identifierType === 3 /* ByteString */) {
|
|
482
|
-
return 5 /* ByteString */;
|
|
483
|
-
}
|
|
484
|
-
throw new CodecError(`Invalid NodeId identifier type: ${nodeId.identifierType}`);
|
|
485
|
-
}
|
|
486
|
-
var ExpandedNodeIdMask = {
|
|
487
|
-
ServerIndexFlag: 64,
|
|
488
|
-
NamespaceUriFlag: 128
|
|
489
|
-
};
|
|
490
|
-
var LocalizedTextMask = {
|
|
491
|
-
LocaleFlag: 1,
|
|
492
|
-
TextFlag: 2
|
|
493
|
-
};
|
|
494
|
-
var DataValueMaskBits = {
|
|
495
|
-
Value: 1,
|
|
496
|
-
StatusCode: 2,
|
|
497
|
-
SourceTimestamp: 4,
|
|
498
|
-
ServerTimestamp: 8,
|
|
499
|
-
SourcePicoseconds: 16,
|
|
500
|
-
ServerPicoseconds: 32
|
|
501
|
-
};
|
|
502
|
-
var DiagnosticInfoMaskBits = {
|
|
503
|
-
SymbolicId: 1,
|
|
504
|
-
NamespaceUri: 2,
|
|
505
|
-
LocalizedText: 4,
|
|
506
|
-
Locale: 8,
|
|
507
|
-
AdditionalInfo: 16,
|
|
508
|
-
InnerStatusCode: 32,
|
|
509
|
-
InnerDiagnosticInfo: 64
|
|
510
|
-
};
|
|
511
|
-
var VariantMask = {
|
|
512
|
-
TypeMask: 63,
|
|
513
|
-
ArrayDimensions: 64,
|
|
514
|
-
Array: 128
|
|
515
|
-
};
|
|
516
|
-
var BinaryWriter = class {
|
|
517
|
-
buffer;
|
|
518
|
-
position;
|
|
519
|
-
getData() {
|
|
520
|
-
return this.buffer.subarray(0, this.position);
|
|
521
|
-
}
|
|
522
|
-
/** Returns the number of bytes written so far. */
|
|
523
|
-
getLength() {
|
|
524
|
-
return this.position;
|
|
525
|
-
}
|
|
526
|
-
/** Appends raw bytes to the buffer. */
|
|
527
|
-
writeBytes(data) {
|
|
528
|
-
this.ensureCapacity(data.length);
|
|
529
|
-
this.buffer.set(data, this.position);
|
|
530
|
-
this.position += data.length;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Overwrites bytes in the buffer starting at the given position.
|
|
534
|
-
* Also truncates the written length to `offset + data.length` if that
|
|
535
|
-
* is less than the current position (i.e. replaces and trims the tail).
|
|
536
|
-
*/
|
|
537
|
-
writeBytesAt(data, offset) {
|
|
538
|
-
const end = offset + data.length;
|
|
539
|
-
this.ensureCapacity(Math.max(0, end - this.position));
|
|
540
|
-
this.buffer.set(data, offset);
|
|
541
|
-
if (end > this.position) {
|
|
542
|
-
this.position = end;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Inserts bytes at the given offset, shifting all subsequent content right.
|
|
547
|
-
*/
|
|
548
|
-
insertBytesAt(data, offset) {
|
|
549
|
-
this.ensureCapacity(data.length);
|
|
550
|
-
this.buffer.copyWithin(offset + data.length, offset, this.position);
|
|
551
|
-
this.buffer.set(data, offset);
|
|
552
|
-
this.position += data.length;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Overwrites a UInt32 (little-endian) at the given byte offset without
|
|
556
|
-
* advancing the write position.
|
|
557
|
-
*/
|
|
558
|
-
writeUInt32At(value, offset) {
|
|
559
|
-
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
560
|
-
throw new CodecError(`UInt32 value ${value} out of range [0, 4294967295]`);
|
|
561
|
-
}
|
|
562
|
-
this.buffer.writeUInt32LE(value, offset);
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Ensure buffer has enough capacity, growing if necessary.
|
|
566
|
-
*/
|
|
567
|
-
ensureCapacity(additionalBytes) {
|
|
568
|
-
const required = this.position + additionalBytes;
|
|
569
|
-
if (required > this.buffer.length) {
|
|
570
|
-
const newSize = Math.max(required, this.buffer.length * 2);
|
|
571
|
-
const newBuffer = Buffer.allocUnsafe(newSize);
|
|
572
|
-
this.buffer.copy(newBuffer, 0, 0, this.position);
|
|
573
|
-
this.buffer = newBuffer;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
writeBoolean(value) {
|
|
577
|
-
this.ensureCapacity(1);
|
|
578
|
-
this.buffer.writeUInt8(value ? 1 : 0, this.position);
|
|
579
|
-
this.position += 1;
|
|
580
|
-
}
|
|
581
|
-
writeByte(value) {
|
|
582
|
-
if (value < 0 || value > 255) {
|
|
583
|
-
throw new CodecError(`Byte value ${value} out of range [0, 255]`);
|
|
584
|
-
}
|
|
585
|
-
this.ensureCapacity(1);
|
|
586
|
-
this.buffer.writeUInt8(value, this.position);
|
|
587
|
-
this.position += 1;
|
|
588
|
-
}
|
|
589
|
-
writeSByte(value) {
|
|
590
|
-
if (value < -128 || value > 127) {
|
|
591
|
-
throw new CodecError(`SByte value ${value} out of range [-128, 127]`);
|
|
592
|
-
}
|
|
593
|
-
this.ensureCapacity(1);
|
|
594
|
-
this.buffer.writeInt8(value, this.position);
|
|
595
|
-
this.position += 1;
|
|
596
|
-
}
|
|
597
|
-
writeInt16(value) {
|
|
598
|
-
if (value < -32768 || value > 32767) {
|
|
599
|
-
throw new CodecError(`Int16 value ${value} out of range [-32768, 32767]`);
|
|
600
|
-
}
|
|
601
|
-
this.ensureCapacity(2);
|
|
602
|
-
this.buffer.writeInt16LE(value, this.position);
|
|
603
|
-
this.position += 2;
|
|
604
|
-
}
|
|
605
|
-
writeUInt16(value) {
|
|
606
|
-
if (value < 0 || value > 65535) {
|
|
607
|
-
throw new CodecError(`UInt16 value ${value} out of range [0, 65535]`);
|
|
608
|
-
}
|
|
609
|
-
this.ensureCapacity(2);
|
|
610
|
-
this.buffer.writeUInt16LE(value, this.position);
|
|
611
|
-
this.position += 2;
|
|
612
|
-
}
|
|
613
|
-
writeInt32(value) {
|
|
614
|
-
if (!Number.isInteger(value) || value < -2147483648 || value > 2147483647) {
|
|
615
|
-
throw new CodecError(`Int32 value ${value} out of range [-2147483648, 2147483647]`);
|
|
616
|
-
}
|
|
617
|
-
this.ensureCapacity(4);
|
|
618
|
-
this.buffer.writeInt32LE(value, this.position);
|
|
619
|
-
this.position += 4;
|
|
620
|
-
}
|
|
621
|
-
writeUInt32(value) {
|
|
622
|
-
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
623
|
-
throw new CodecError(`UInt32 value ${value} out of range [0, 4294967295]`);
|
|
624
|
-
}
|
|
625
|
-
this.ensureCapacity(4);
|
|
626
|
-
this.buffer.writeUInt32LE(value, this.position);
|
|
627
|
-
this.position += 4;
|
|
628
|
-
}
|
|
629
|
-
writeInt64(value) {
|
|
630
|
-
this.ensureCapacity(8);
|
|
631
|
-
this.buffer.writeBigInt64LE(value, this.position);
|
|
632
|
-
this.position += 8;
|
|
633
|
-
}
|
|
634
|
-
writeUInt64(value) {
|
|
635
|
-
this.ensureCapacity(8);
|
|
636
|
-
this.buffer.writeBigUInt64LE(value, this.position);
|
|
637
|
-
this.position += 8;
|
|
638
|
-
}
|
|
639
|
-
writeFloat(value) {
|
|
640
|
-
this.ensureCapacity(4);
|
|
641
|
-
this.buffer.writeFloatLE(value, this.position);
|
|
642
|
-
this.position += 4;
|
|
643
|
-
}
|
|
644
|
-
writeDouble(value) {
|
|
645
|
-
this.ensureCapacity(8);
|
|
646
|
-
this.buffer.writeDoubleLE(value, this.position);
|
|
647
|
-
this.position += 8;
|
|
648
|
-
}
|
|
649
|
-
writeString(value) {
|
|
650
|
-
if (value == null) {
|
|
651
|
-
this.writeInt32(-1);
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
const utf8Bytes = Buffer.from(value, "utf8");
|
|
655
|
-
const length = utf8Bytes.length;
|
|
656
|
-
if (length > 16777216) {
|
|
657
|
-
throw new CodecError(
|
|
658
|
-
`String length ${length} exceeds maximum allowed length of 16,777,216 bytes`,
|
|
659
|
-
{ format: "Binary", suggestedAction: "Reduce string length" }
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
this.writeInt32(length);
|
|
663
|
-
this.ensureCapacity(length);
|
|
664
|
-
utf8Bytes.copy(this.buffer, this.position);
|
|
665
|
-
this.position += length;
|
|
666
|
-
}
|
|
667
|
-
writeDateTime(value) {
|
|
668
|
-
const jsTimestamp = BigInt(value.getTime());
|
|
669
|
-
const opcTimestamp = (jsTimestamp + EPOCH_DIFF_MS) * TICKS_PER_MS;
|
|
670
|
-
this.writeInt64(opcTimestamp);
|
|
671
|
-
}
|
|
672
|
-
writeGuid(value) {
|
|
673
|
-
const hex = value.replace(/-/g, "");
|
|
674
|
-
if (hex.length !== 32) {
|
|
675
|
-
throw new CodecError(`Invalid GUID format: ${value}`);
|
|
676
|
-
}
|
|
677
|
-
this.ensureCapacity(16);
|
|
678
|
-
const data1 = parseInt(hex.substr(0, 8), 16);
|
|
679
|
-
this.buffer.writeUInt32LE(data1, this.position);
|
|
680
|
-
const data2 = parseInt(hex.substr(8, 4), 16);
|
|
681
|
-
this.buffer.writeUInt16LE(data2, this.position + 4);
|
|
682
|
-
const data3 = parseInt(hex.substr(12, 4), 16);
|
|
683
|
-
this.buffer.writeUInt16LE(data3, this.position + 6);
|
|
684
|
-
for (let i = 0; i < 8; i++) {
|
|
685
|
-
const byte = parseInt(hex.substr(16 + i * 2, 2), 16);
|
|
686
|
-
this.buffer.writeUInt8(byte, this.position + 8 + i);
|
|
687
|
-
}
|
|
688
|
-
this.position += 16;
|
|
689
|
-
}
|
|
690
|
-
writeByteString(value) {
|
|
691
|
-
if (value == null) {
|
|
692
|
-
this.writeInt32(-1);
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
const length = value.length;
|
|
696
|
-
if (length > 16777216) {
|
|
697
|
-
throw new CodecError(
|
|
698
|
-
`ByteString length ${length} exceeds maximum allowed length of 16,777,216 bytes`,
|
|
699
|
-
{ format: "Binary", suggestedAction: "Reduce ByteString length" }
|
|
700
|
-
);
|
|
701
|
-
}
|
|
702
|
-
this.writeInt32(length);
|
|
703
|
-
this.ensureCapacity(length);
|
|
704
|
-
if (Buffer.isBuffer(value)) {
|
|
705
|
-
value.copy(this.buffer, this.position);
|
|
706
|
-
} else {
|
|
707
|
-
this.buffer.set(value, this.position);
|
|
708
|
-
}
|
|
709
|
-
this.position += length;
|
|
710
|
-
}
|
|
711
|
-
writeXmlElement(value) {
|
|
712
|
-
this.writeString(value);
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
* Write an array with Int32 length prefix.
|
|
716
|
-
* Per FR-011: -1 = null, 0 = empty, positive = element count
|
|
717
|
-
* Per FR-019: Maximum array length is 2,147,483,647 elements
|
|
718
|
-
*
|
|
719
|
-
* @param array The array to encode (undefined for null array)
|
|
720
|
-
* @param encodeElement Function to encode each element
|
|
721
|
-
* @throws {CodecError} if array length exceeds Int32 maximum
|
|
722
|
-
* @see OPC 10000-6 Section 5.2.5 - Arrays
|
|
723
|
-
*/
|
|
724
|
-
writeArray(array, encodeElement) {
|
|
725
|
-
if (array === void 0) {
|
|
726
|
-
this.writeInt32(-1);
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
const length = array.length;
|
|
730
|
-
if (length > 2147483647) {
|
|
731
|
-
throw new CodecError(
|
|
732
|
-
`Array length ${length} exceeds maximum allowed length of 2,147,483,647 elements`,
|
|
733
|
-
{ format: "Binary", suggestedAction: "Reduce array size" }
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
this.writeInt32(length);
|
|
737
|
-
for (const element of array) {
|
|
738
|
-
encodeElement(this, element);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
// === Complex type write methods ===
|
|
742
|
-
/**
|
|
743
|
-
* Encode a NodeId in binary format using the most compact representation.
|
|
744
|
-
* @see OPC 10000-6 Tables 16-19
|
|
745
|
-
*/
|
|
746
|
-
writeNodeId(value) {
|
|
747
|
-
const format = selectNodeIdEncodingFormat(value);
|
|
748
|
-
switch (format) {
|
|
749
|
-
case 0 /* TwoByte */:
|
|
750
|
-
this.writeByte(0 /* TwoByte */);
|
|
751
|
-
this.writeByte(value.identifier);
|
|
752
|
-
break;
|
|
753
|
-
case 1 /* FourByte */:
|
|
754
|
-
this.writeByte(1 /* FourByte */);
|
|
755
|
-
this.writeByte(value.namespace);
|
|
756
|
-
this.writeUInt16(value.identifier);
|
|
757
|
-
break;
|
|
758
|
-
case 2 /* Numeric */:
|
|
759
|
-
this.writeByte(2 /* Numeric */);
|
|
760
|
-
this.writeUInt16(value.namespace);
|
|
761
|
-
this.writeUInt32(value.identifier);
|
|
762
|
-
break;
|
|
763
|
-
case 3 /* String */:
|
|
764
|
-
this.writeByte(3 /* String */);
|
|
765
|
-
this.writeUInt16(value.namespace);
|
|
766
|
-
this.writeString(value.identifier);
|
|
767
|
-
break;
|
|
768
|
-
case 4 /* Guid */:
|
|
769
|
-
this.writeByte(4 /* Guid */);
|
|
770
|
-
this.writeUInt16(value.namespace);
|
|
771
|
-
this.writeGuid(value.identifier);
|
|
772
|
-
break;
|
|
773
|
-
case 5 /* ByteString */: {
|
|
774
|
-
this.writeByte(5 /* ByteString */);
|
|
775
|
-
this.writeUInt16(value.namespace);
|
|
776
|
-
const ident = value.identifier;
|
|
777
|
-
const buf = ident instanceof Uint8Array && !(ident instanceof Buffer) ? Buffer.from(ident) : ident;
|
|
778
|
-
this.writeByteString(buf);
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
default:
|
|
782
|
-
throw new CodecError(`Unsupported NodeId encoding format: ${format}`);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Encode an ExpandedNodeId in binary format.
|
|
787
|
-
* @see OPC 10000-6 Table 20
|
|
788
|
-
*/
|
|
789
|
-
writeExpandedNodeId(value) {
|
|
790
|
-
const startPos = this.position;
|
|
791
|
-
this.writeNodeId(value);
|
|
792
|
-
let encodingByte = this.buffer[startPos];
|
|
793
|
-
if (value.namespaceUri !== void 0) {
|
|
794
|
-
encodingByte |= ExpandedNodeIdMask.NamespaceUriFlag;
|
|
795
|
-
}
|
|
796
|
-
if (value.serverIndex !== void 0) {
|
|
797
|
-
encodingByte |= ExpandedNodeIdMask.ServerIndexFlag;
|
|
798
|
-
}
|
|
799
|
-
this.buffer[startPos] = encodingByte;
|
|
800
|
-
if (value.namespaceUri !== void 0) {
|
|
801
|
-
this.writeString(value.namespaceUri);
|
|
802
|
-
}
|
|
803
|
-
if (value.serverIndex !== void 0) {
|
|
804
|
-
this.writeUInt32(value.serverIndex);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Encode a StatusCode as a UInt32.
|
|
809
|
-
* @see OPC 10000-6 Section 5.2.2.16
|
|
810
|
-
*/
|
|
811
|
-
writeStatusCode(value) {
|
|
812
|
-
this.writeUInt32(value);
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Encode a QualifiedName as NamespaceIndex (UInt16) + Name (String).
|
|
816
|
-
* @see OPC 10000-6 Table 8
|
|
817
|
-
*/
|
|
818
|
-
writeQualifiedName(value) {
|
|
819
|
-
this.writeUInt16(value.namespaceIndex);
|
|
820
|
-
this.writeString(value.name);
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Encode a LocalizedText with optional locale and text.
|
|
824
|
-
* @see OPC 10000-6 Table 9
|
|
825
|
-
*/
|
|
826
|
-
writeLocalizedText(value) {
|
|
827
|
-
let encodingMask = 0;
|
|
828
|
-
if (value.locale !== void 0 && value.locale !== "") {
|
|
829
|
-
encodingMask |= LocalizedTextMask.LocaleFlag;
|
|
830
|
-
}
|
|
831
|
-
if (value.text !== "") {
|
|
832
|
-
encodingMask |= LocalizedTextMask.TextFlag;
|
|
833
|
-
}
|
|
834
|
-
this.writeByte(encodingMask);
|
|
835
|
-
if (encodingMask & LocalizedTextMask.LocaleFlag) {
|
|
836
|
-
this.writeString(value.locale);
|
|
837
|
-
}
|
|
838
|
-
if (encodingMask & LocalizedTextMask.TextFlag) {
|
|
839
|
-
this.writeString(value.text);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* Encode an ExtensionObject with its TypeId and body.
|
|
844
|
-
* @see OPC 10000-6 Section 5.2.2.15
|
|
845
|
-
*/
|
|
846
|
-
writeExtensionObject(value, encoder) {
|
|
847
|
-
const typeId = value.typeId;
|
|
848
|
-
if ("namespaceUri" in typeId || "serverIndex" in typeId) {
|
|
849
|
-
this.writeExpandedNodeId(typeId);
|
|
850
|
-
} else {
|
|
851
|
-
this.writeNodeId(typeId);
|
|
852
|
-
}
|
|
853
|
-
this.writeByte(value.encoding);
|
|
854
|
-
switch (value.encoding) {
|
|
855
|
-
case 0 /* None */:
|
|
856
|
-
break;
|
|
857
|
-
case 1 /* Binary */:
|
|
858
|
-
if (!value.data) {
|
|
859
|
-
throw new CodecError("ExtensionObject with Binary encoding must have data");
|
|
860
|
-
}
|
|
861
|
-
const binaryData = encoder.encodeWithoutId(value.data, "binary");
|
|
862
|
-
this.writeByteString(binaryData);
|
|
863
|
-
break;
|
|
864
|
-
case 2 /* Xml */:
|
|
865
|
-
if (!value.data) {
|
|
866
|
-
throw new CodecError("ExtensionObject with Xml encoding must have data");
|
|
867
|
-
}
|
|
868
|
-
const xmlString = encoder.encodeWithoutId(value.data, "xml");
|
|
869
|
-
this.writeXmlElement(xmlString);
|
|
870
|
-
break;
|
|
871
|
-
default:
|
|
872
|
-
throw new CodecError(`Invalid ExtensionObject encoding: ${value.encoding}`);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Encode a DataValue with optional fields controlled by an encoding mask.
|
|
877
|
-
* @see OPC 10000-6 Table 26
|
|
878
|
-
*/
|
|
879
|
-
writeDataValue(value, encoder) {
|
|
880
|
-
let encodingMask = 0;
|
|
881
|
-
if (value.value !== null && value.value !== void 0) {
|
|
882
|
-
encodingMask |= DataValueMaskBits.Value;
|
|
883
|
-
}
|
|
884
|
-
if (value.statusCode !== null) {
|
|
885
|
-
encodingMask |= DataValueMaskBits.StatusCode;
|
|
886
|
-
}
|
|
887
|
-
if (value.sourceTimestamp !== null) {
|
|
888
|
-
encodingMask |= DataValueMaskBits.SourceTimestamp;
|
|
889
|
-
}
|
|
890
|
-
if (value.serverTimestamp !== null) {
|
|
891
|
-
encodingMask |= DataValueMaskBits.ServerTimestamp;
|
|
892
|
-
}
|
|
893
|
-
if (value.sourcePicoseconds !== null) {
|
|
894
|
-
encodingMask |= DataValueMaskBits.SourcePicoseconds;
|
|
895
|
-
}
|
|
896
|
-
if (value.serverPicoseconds !== null) {
|
|
897
|
-
encodingMask |= DataValueMaskBits.ServerPicoseconds;
|
|
898
|
-
}
|
|
899
|
-
this.writeByte(encodingMask);
|
|
900
|
-
if (encodingMask & DataValueMaskBits.Value) {
|
|
901
|
-
this.writeVariant(value.value, encoder);
|
|
902
|
-
}
|
|
903
|
-
if (encodingMask & DataValueMaskBits.StatusCode) {
|
|
904
|
-
this.writeUInt32(value.statusCode ?? 0 /* Good */);
|
|
905
|
-
}
|
|
906
|
-
if (encodingMask & DataValueMaskBits.SourceTimestamp) {
|
|
907
|
-
this.writeDateTime(value.sourceTimestamp);
|
|
908
|
-
}
|
|
909
|
-
if (encodingMask & DataValueMaskBits.ServerTimestamp) {
|
|
910
|
-
this.writeDateTime(value.serverTimestamp);
|
|
911
|
-
}
|
|
912
|
-
if (encodingMask & DataValueMaskBits.SourcePicoseconds) {
|
|
913
|
-
this.writeUInt16(value.sourcePicoseconds);
|
|
914
|
-
}
|
|
915
|
-
if (encodingMask & DataValueMaskBits.ServerPicoseconds) {
|
|
916
|
-
this.writeUInt16(value.serverPicoseconds);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Encode a Variant with type ID, value(s), and optional array dimensions.
|
|
921
|
-
* @see OPC 10000-6 Section 5.2.2.16
|
|
922
|
-
*/
|
|
923
|
-
writeVariant(value, encoder) {
|
|
924
|
-
if (value.variantType < 0 || value.variantType > 25) {
|
|
925
|
-
throw new CodecError(`Invalid Variant type ID: ${value.variantType}. Must be 0-25.`);
|
|
926
|
-
}
|
|
927
|
-
let mask = value.variantType & VariantMask.TypeMask;
|
|
928
|
-
const isArrayValue = Array.isArray(value.value);
|
|
929
|
-
if (isArrayValue) {
|
|
930
|
-
mask |= VariantMask.Array;
|
|
931
|
-
}
|
|
932
|
-
if (value.arrayDimensions !== void 0 && value.arrayDimensions.length > 0) {
|
|
933
|
-
mask |= VariantMask.ArrayDimensions;
|
|
934
|
-
}
|
|
935
|
-
this.writeByte(mask);
|
|
936
|
-
if (isArrayValue) {
|
|
937
|
-
const array = value.value;
|
|
938
|
-
this.writeInt32(array.length);
|
|
939
|
-
for (const elem of array) {
|
|
940
|
-
this.writeVariantValue(value.variantType, elem, encoder);
|
|
941
|
-
}
|
|
942
|
-
} else if (value.variantType !== 0 /* Null */) {
|
|
943
|
-
this.writeVariantValue(value.variantType, value.value, encoder);
|
|
944
|
-
}
|
|
945
|
-
if (value.arrayDimensions !== void 0 && value.arrayDimensions.length > 0) {
|
|
946
|
-
this.writeInt32(value.arrayDimensions.length);
|
|
947
|
-
for (const dim of value.arrayDimensions) {
|
|
948
|
-
this.writeInt32(dim);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Encode a DiagnosticInfo with optional fields controlled by an encoding mask.
|
|
954
|
-
* Supports recursive InnerDiagnosticInfo.
|
|
955
|
-
* @see OPC 10000-6 Table 24
|
|
956
|
-
*/
|
|
957
|
-
writeDiagnosticInfo(value) {
|
|
958
|
-
let encodingMask = 0;
|
|
959
|
-
if (value.symbolicId !== null) {
|
|
960
|
-
encodingMask |= DiagnosticInfoMaskBits.SymbolicId;
|
|
961
|
-
}
|
|
962
|
-
if (value.namespaceUri !== null) {
|
|
963
|
-
encodingMask |= DiagnosticInfoMaskBits.NamespaceUri;
|
|
964
|
-
}
|
|
965
|
-
if (value.localizedText !== null) {
|
|
966
|
-
encodingMask |= DiagnosticInfoMaskBits.LocalizedText;
|
|
967
|
-
}
|
|
968
|
-
if (value.locale !== null) {
|
|
969
|
-
encodingMask |= DiagnosticInfoMaskBits.Locale;
|
|
970
|
-
}
|
|
971
|
-
if (value.additionalInfo !== null) {
|
|
972
|
-
encodingMask |= DiagnosticInfoMaskBits.AdditionalInfo;
|
|
973
|
-
}
|
|
974
|
-
if (value.innerStatusCode !== null) {
|
|
975
|
-
encodingMask |= DiagnosticInfoMaskBits.InnerStatusCode;
|
|
976
|
-
}
|
|
977
|
-
if (value.innerDiagnosticInfo !== null) {
|
|
978
|
-
encodingMask |= DiagnosticInfoMaskBits.InnerDiagnosticInfo;
|
|
979
|
-
}
|
|
980
|
-
this.writeByte(encodingMask);
|
|
981
|
-
if (encodingMask & DiagnosticInfoMaskBits.SymbolicId) {
|
|
982
|
-
this.writeInt32(value.symbolicId);
|
|
983
|
-
}
|
|
984
|
-
if (encodingMask & DiagnosticInfoMaskBits.NamespaceUri) {
|
|
985
|
-
this.writeInt32(value.namespaceUri);
|
|
986
|
-
}
|
|
987
|
-
if (encodingMask & DiagnosticInfoMaskBits.LocalizedText) {
|
|
988
|
-
this.writeInt32(value.localizedText);
|
|
989
|
-
}
|
|
990
|
-
if (encodingMask & DiagnosticInfoMaskBits.Locale) {
|
|
991
|
-
this.writeInt32(value.locale);
|
|
992
|
-
}
|
|
993
|
-
if (encodingMask & DiagnosticInfoMaskBits.AdditionalInfo) {
|
|
994
|
-
this.writeString(value.additionalInfo);
|
|
995
|
-
}
|
|
996
|
-
if (encodingMask & DiagnosticInfoMaskBits.InnerStatusCode) {
|
|
997
|
-
this.writeUInt32(value.innerStatusCode ?? 0 /* Good */);
|
|
998
|
-
}
|
|
999
|
-
if (encodingMask & DiagnosticInfoMaskBits.InnerDiagnosticInfo) {
|
|
1000
|
-
this.writeDiagnosticInfo(value.innerDiagnosticInfo);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
// === Private helpers ===
|
|
1004
|
-
writeVariantValue(type, value, encoder) {
|
|
1005
|
-
switch (type) {
|
|
1006
|
-
case 0 /* Null */:
|
|
1007
|
-
break;
|
|
1008
|
-
case 1 /* Boolean */:
|
|
1009
|
-
this.writeBoolean(value);
|
|
1010
|
-
break;
|
|
1011
|
-
case 2 /* SByte */:
|
|
1012
|
-
this.writeSByte(value);
|
|
1013
|
-
break;
|
|
1014
|
-
case 3 /* Byte */:
|
|
1015
|
-
this.writeByte(value);
|
|
1016
|
-
break;
|
|
1017
|
-
case 4 /* Int16 */:
|
|
1018
|
-
this.writeInt16(value);
|
|
1019
|
-
break;
|
|
1020
|
-
case 5 /* UInt16 */:
|
|
1021
|
-
this.writeUInt16(value);
|
|
1022
|
-
break;
|
|
1023
|
-
case 6 /* Int32 */:
|
|
1024
|
-
this.writeInt32(value);
|
|
1025
|
-
break;
|
|
1026
|
-
case 7 /* UInt32 */:
|
|
1027
|
-
this.writeUInt32(value);
|
|
1028
|
-
break;
|
|
1029
|
-
case 8 /* Int64 */:
|
|
1030
|
-
this.writeInt64(value);
|
|
1031
|
-
break;
|
|
1032
|
-
case 9 /* UInt64 */:
|
|
1033
|
-
this.writeUInt64(value);
|
|
1034
|
-
break;
|
|
1035
|
-
case 10 /* Float */:
|
|
1036
|
-
this.writeFloat(value);
|
|
1037
|
-
break;
|
|
1038
|
-
case 11 /* Double */:
|
|
1039
|
-
this.writeDouble(value);
|
|
1040
|
-
break;
|
|
1041
|
-
case 12 /* String */:
|
|
1042
|
-
this.writeString(value);
|
|
1043
|
-
break;
|
|
1044
|
-
case 13 /* DateTime */:
|
|
1045
|
-
this.writeDateTime(value);
|
|
1046
|
-
break;
|
|
1047
|
-
case 14 /* Guid */:
|
|
1048
|
-
this.writeGuid(value);
|
|
1049
|
-
break;
|
|
1050
|
-
case 15 /* ByteString */:
|
|
1051
|
-
this.writeByteString(value);
|
|
1052
|
-
break;
|
|
1053
|
-
case 16 /* XmlElement */:
|
|
1054
|
-
this.writeXmlElement(value);
|
|
1055
|
-
break;
|
|
1056
|
-
case 17 /* NodeId */:
|
|
1057
|
-
this.writeNodeId(value);
|
|
1058
|
-
break;
|
|
1059
|
-
case 18 /* ExpandedNodeId */:
|
|
1060
|
-
this.writeExpandedNodeId(value);
|
|
1061
|
-
break;
|
|
1062
|
-
case 19 /* StatusCode */:
|
|
1063
|
-
this.writeStatusCode(value);
|
|
1064
|
-
break;
|
|
1065
|
-
case 20 /* QualifiedName */:
|
|
1066
|
-
this.writeQualifiedName(value);
|
|
1067
|
-
break;
|
|
1068
|
-
case 21 /* LocalizedText */:
|
|
1069
|
-
this.writeLocalizedText(value);
|
|
1070
|
-
break;
|
|
1071
|
-
case 22 /* ExtensionObject */:
|
|
1072
|
-
this.writeExtensionObject(value, encoder);
|
|
1073
|
-
break;
|
|
1074
|
-
case 23 /* DataValue */:
|
|
1075
|
-
this.writeDataValue(value, encoder);
|
|
1076
|
-
break;
|
|
1077
|
-
case 24 /* Variant */:
|
|
1078
|
-
this.writeVariant(value, encoder);
|
|
1079
|
-
break;
|
|
1080
|
-
case 25 /* DiagnosticInfo */:
|
|
1081
|
-
this.writeDiagnosticInfo(value);
|
|
1082
|
-
break;
|
|
1083
|
-
default:
|
|
1084
|
-
throw new CodecError(`Unsupported Variant type: ${type}`);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
constructor(initialSize = 1024) {
|
|
1088
|
-
this.buffer = Buffer.allocUnsafe(initialSize);
|
|
1089
|
-
this.position = 0;
|
|
1090
|
-
}
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
// src/configurationClient.ts
|
|
1094
|
-
var ConfigurationClient = class _ConfigurationClient extends base.Configuration {
|
|
400
|
+
var ConfigurationClient = class _ConfigurationClient extends opcjsBase.Configuration {
|
|
1095
401
|
static getSimple(name, company) {
|
|
1096
402
|
const applicationUri = `urn:${company}:${name}`;
|
|
1097
403
|
const productUri = `urn:${company}:${name}:product`;
|
|
1098
|
-
const encoder = new
|
|
404
|
+
const encoder = new opcjsBase.Encoder();
|
|
1099
405
|
encoder.registerWriterFactory("binary", () => {
|
|
1100
|
-
return new BinaryWriter();
|
|
406
|
+
return new opcjsBase.BinaryWriter();
|
|
1101
407
|
});
|
|
1102
|
-
|
|
1103
|
-
const decoder = new
|
|
408
|
+
opcjsBase.registerEncoders(encoder);
|
|
409
|
+
const decoder = new opcjsBase.Decoder();
|
|
1104
410
|
decoder.registerReaderFactory("binary", (data) => {
|
|
1105
|
-
return new
|
|
411
|
+
return new opcjsBase.BinaryReader(data);
|
|
1106
412
|
});
|
|
1107
|
-
|
|
1108
|
-
|
|
413
|
+
opcjsBase.registerTypeDecoders(decoder);
|
|
414
|
+
opcjsBase.registerBinaryDecoders(decoder);
|
|
1109
415
|
return new _ConfigurationClient(name, applicationUri, name, productUri, encoder, decoder);
|
|
1110
416
|
}
|
|
1111
417
|
constructor(applicationName, applicationUri, productName, productUri, encoder, decoder) {
|
|
@@ -1117,7 +423,7 @@ var Id = class _Id {
|
|
|
1117
423
|
this.nodeId = nodeId;
|
|
1118
424
|
}
|
|
1119
425
|
static newId(namespace, identifier) {
|
|
1120
|
-
return new _Id(new
|
|
426
|
+
return new _Id(new opcjsBase.NodeId(namespace, identifier));
|
|
1121
427
|
}
|
|
1122
428
|
toNodeId() {
|
|
1123
429
|
return this.nodeId;
|
|
@@ -1128,30 +434,30 @@ var Id = class _Id {
|
|
|
1128
434
|
};
|
|
1129
435
|
var UserIdentity = class _UserIdentity {
|
|
1130
436
|
userIdentityToken;
|
|
1131
|
-
tokenType =
|
|
437
|
+
tokenType = opcjsBase.UserTokenTypeEnum.Anonymous;
|
|
1132
438
|
issuerLoginCallback = void 0;
|
|
1133
439
|
static newAnonymous() {
|
|
1134
440
|
const userIdentity = new _UserIdentity();
|
|
1135
|
-
userIdentity.userIdentityToken = new
|
|
441
|
+
userIdentity.userIdentityToken = new opcjsBase.AnonymousIdentityToken();
|
|
1136
442
|
userIdentity.userIdentityToken.policyId = "anonymous";
|
|
1137
|
-
userIdentity.tokenType =
|
|
443
|
+
userIdentity.tokenType = opcjsBase.UserTokenTypeEnum.Anonymous;
|
|
1138
444
|
return userIdentity;
|
|
1139
445
|
}
|
|
1140
446
|
static newWithUserName(userName, password) {
|
|
1141
447
|
const userIdentity = new _UserIdentity();
|
|
1142
|
-
const nameToken = new
|
|
448
|
+
const nameToken = new opcjsBase.UserNameIdentityToken();
|
|
1143
449
|
nameToken.userName = userName;
|
|
1144
450
|
nameToken.password = new TextEncoder().encode(password);
|
|
1145
451
|
userIdentity.userIdentityToken = nameToken;
|
|
1146
|
-
userIdentity.tokenType =
|
|
452
|
+
userIdentity.tokenType = opcjsBase.UserTokenTypeEnum.UserName;
|
|
1147
453
|
return userIdentity;
|
|
1148
454
|
}
|
|
1149
455
|
static newWithIssuerToken(loginCallback) {
|
|
1150
456
|
const userIdentity = new _UserIdentity();
|
|
1151
|
-
const issuedToken = new
|
|
457
|
+
const issuedToken = new opcjsBase.IssuedIdentityToken();
|
|
1152
458
|
issuedToken.tokenData = new TextEncoder().encode("");
|
|
1153
459
|
userIdentity.userIdentityToken = issuedToken;
|
|
1154
|
-
userIdentity.tokenType =
|
|
460
|
+
userIdentity.tokenType = opcjsBase.UserTokenTypeEnum.IssuedToken;
|
|
1155
461
|
userIdentity.issuerLoginCallback = loginCallback;
|
|
1156
462
|
return userIdentity;
|
|
1157
463
|
}
|