Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua-guid' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
constructor(identifierType: NodeIdType, value: any, namespace?: number) {
this.identifierType = identifierType;
this.value = value;
this.namespace = namespace || 0;
// namespace shall be a UInt16
assert(this.namespace >= 0 && this.namespace <= 0xFFFF);
assert(this.identifierType !== NodeIdType.NUMERIC || (this.value >= 0 && this.value <= 0xFFFFFFFF));
assert(this.identifierType !== NodeIdType.GUID || isValidGuid(this.value as string));
assert(this.identifierType !== NodeIdType.STRING || typeof this.value === "string");
}
export function makeNodeId(value: string | Buffer | number, namespace?: number) {
value = value || 0;
namespace = namespace || 0;
let identifierType = NodeIdType.NUMERIC;
if (typeof value === "string") {
if (value.match(/^(s|g|b|i)=/)) {
throw new Error("please use coerce NodeId instead");
}
// 1 2 3
// 012345678901234567890123456789012345
// "72962B91-FA75-4AE6-8D28-B404DC7DAF63"
if (isValidGuid(value)) {
identifierType = NodeIdType.GUID;
} else {
identifierType = NodeIdType.STRING;
// detect accidental string of form "ns=x;x";
assert(value.indexOf("ns=") === -1, " makeNodeId(string) ? did you mean using coerceNodeId instead? ");
}
} else if (value instanceof Buffer) {
identifierType = NodeIdType.BYTESTRING;
}
const nodeId = new NodeId(identifierType, value, namespace);
assert(nodeId.hasOwnProperty("identifierType"));
return nodeId;
}
export function encodeGuid(guid: Guid, stream: BinaryStream): void {
if (!isValidGuid(guid)) {
throw new Error(" Invalid GUID : '" + JSON.stringify(guid) + "'");
}
// 1 2 3
// 012345678901234567890123456789012345
// | | | | | | | | | | |
// 12345678-1234-1234-ABCD-0123456789AB
// 00000000-0000-0000-0000-000000000000";
function write_UInt32(starts: number[]) {
const n = starts.length;
for (let i = 0; i < n; i++) {
const start = starts[i];
stream.writeUInt32(parseInt(guid.substr(start, 8), 16));
}
}
function write_UInt16(starts: number[]) {
"use strict";
/**
* @module opcua.miscellaneous
*/
const _ = require("underscore");
const assert = require("node-opcua-assert").assert;
const util = require("util");
const ec = require("node-opcua-basic-types");
const sc = require("node-opcua-status-code");
const emptyGuid = require("node-opcua-guid").emptyGuid;
exports.minDate = new Date(Date.UTC(1601, 0, 1, 0, 0));
//there are 4 types of DataTypes in opcua:
// Built-In DataType
// Simple DataType
// Complex DataType
// Enumeration
const defaultXmlElement = "";
// Built-In Type
} else if (twoFirst === "s=") {
identifierType = NodeIdType.STRING;
value = value.substr(2);
} else if (twoFirst === "b=") {
identifierType = NodeIdType.BYTESTRING;
value = Buffer.from(value.substr(2), "hex");
} else if (twoFirst === "g=") {
identifierType = NodeIdType.GUID;
value = value.substr(2);
} else if (isValidGuid(value)) {
identifierType = NodeIdType.GUID;
} else if ((matches = regexNamespaceI.exec(value)) !== null) {
identifierType = NodeIdType.NUMERIC;
namespace = parseInt(matches[1], 10);
value = parseInt(matches[2], 10);
} else if ((matches = regexNamespaceS.exec(value)) !== null) {
identifierType = NodeIdType.STRING;
namespace = parseInt(matches[1], 10);
value = matches[2];
} else if ((matches = regexNamespaceB.exec(value)) !== null) {
identifierType = NodeIdType.BYTESTRING;