node-opcua-extension-object
Advanced tools
Comparing version 2.6.0-alpha.7 to 2.6.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeExtensionObject = exports.OpaqueStructure = exports.encodeExtensionObject = exports.ExtensionObject = void 0; | ||
/** | ||
* @module node-opcua-extension-object | ||
*/ | ||
const node_opcua_basic_types_1 = require("node-opcua-basic-types"); | ||
@@ -10,3 +13,4 @@ const node_opcua_debug_1 = require("node-opcua-debug"); | ||
const chalk = require("chalk"); | ||
let ExtensionObject = (() => { | ||
/* tslint:disable:no-empty */ | ||
let ExtensionObject = /** @class */ (() => { | ||
class ExtensionObject extends node_opcua_factory_1.BaseUAObject { | ||
@@ -30,11 +34,39 @@ constructor(options) { | ||
} | ||
// OPC-UA Part 6 - $5.2.2.15 ExtensionObject | ||
// An ExtensionObject is encoded as sequence of bytes prefixed by the NodeId of its | ||
// DataTypeEncoding and the number of bytes encoded. | ||
// what the specs say: OCC/UA part 6 $5.2.2.15 ExtensionObject | ||
// | ||
// TypeId | NodeId | The identifier for the DataTypeEncoding node in the Server's AddressSpace. | ||
// | ExtensionObjects defined by the OPC UA specification have a numeric node | ||
// | identifier assigned to them with a NamespaceIndex of 0. The numeric | ||
// | identifiers are defined in A.1. | ||
// | ||
// Encoding | Byte | An enumeration that indicates how the body is encoded. | ||
// | The parameter may have the following values: | ||
// | 0x00 No body is encoded. | ||
// | 0x01 The body is encoded as a ByteString. | ||
// | 0x02 The body is encoded as a XmlElement. | ||
// | ||
// Length | Int32 | The length of the object body. | ||
// | The length shall be specified if the body is encoded. <<<<<<<( WTF ?) | ||
// | ||
// Body | Byte[*] | The object body | ||
// | This field contains the raw bytes for ByteString bodies. | ||
// | For XmlElement bodies this field contains the XML encoded as a UTF-8 | ||
// | string without any null terminator. | ||
// | ||
function encodeExtensionObject(object, stream) { | ||
if (!object) { | ||
node_opcua_basic_types_1.encodeNodeId(node_opcua_nodeid_1.makeNodeId(0), stream); | ||
stream.writeUInt8(0x00); | ||
stream.writeUInt8(0x00); // no body is encoded | ||
// note : Length shall not hbe specified, end of the job! | ||
} | ||
else { | ||
/* istanbul ignore next */ | ||
if (!(object instanceof node_opcua_factory_1.BaseUAObject)) { | ||
throw new Error("Expecting a extension object"); | ||
} | ||
// ensure we have a valid encoding Default Binary ID !!! | ||
/* istanbul ignore next */ | ||
if (!object.schema) { | ||
@@ -45,2 +77,3 @@ debugLog(" object = ", object); | ||
const encodingDefaultBinary = object.schema.encodingDefaultBinary; | ||
/* istanbul ignore next */ | ||
if (!encodingDefaultBinary) { | ||
@@ -50,2 +83,3 @@ debugLog(chalk.yellow("encoding ExtObj "), object); | ||
} | ||
/* istanbul ignore next */ | ||
if (encodingDefaultBinary.isEmpty()) { | ||
@@ -55,2 +89,3 @@ debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString()); | ||
} | ||
/* istanbul ignore next */ | ||
if (node_opcua_factory_1.is_internal_id(encodingDefaultBinary.value)) { | ||
@@ -61,3 +96,3 @@ debugLog(chalk.yellow("encoding ExtObj "), object.constructor.encodingDefaultBinary.toString(), object.schema.name); | ||
node_opcua_basic_types_1.encodeNodeId(encodingDefaultBinary, stream); | ||
stream.writeUInt8(0x01); | ||
stream.writeUInt8(0x01); // 0x01 The body is encoded as a ByteString. | ||
stream.writeUInt32(object.binaryStoreSize()); | ||
@@ -68,2 +103,3 @@ object.encode(stream); | ||
exports.encodeExtensionObject = encodeExtensionObject; | ||
// tslint:disable:max-classes-per-file | ||
class OpaqueStructure extends ExtensionObject { | ||
@@ -91,8 +127,16 @@ constructor(nodeId, buffer) { | ||
const length = stream.readUInt32(); | ||
/* istanbul ignore next */ | ||
if (nodeId.value === 0 || encodingType === 0) { | ||
return {}; | ||
} | ||
// let verify that decode will use the expected number of bytes | ||
const streamLengthBefore = stream.length; | ||
let object; | ||
if (nodeId.namespace !== 0) { | ||
// this is a extension object define in a other namespace | ||
// we can only threat it as an opaque object for the time being | ||
// the caller that may now more about the namespace Array and type | ||
// definition will be able to turn the opaque object into a meaningful | ||
// structure | ||
// lets rewind before the length | ||
stream.length -= 4; | ||
@@ -103,3 +147,5 @@ object = new OpaqueStructure(nodeId, stream.readByteStream()); | ||
object = constructEmptyExtensionObject(nodeId); | ||
/* istanbul ignore next */ | ||
if (object === null) { | ||
// this object is unknown to us .. | ||
stream.length += length; | ||
@@ -118,3 +164,7 @@ object = {}; | ||
if (streamLengthBefore + length !== stream.length) { | ||
// this may happen if the server or client do have a different OPCUA version | ||
// for instance SubscriptionDiagnostics structure has been changed between OPCUA version 1.01 and 1.04 | ||
// causing 2 extra member to be added. | ||
debugLog(chalk.bgWhiteBright.red("=========================================")); | ||
// tslint:disable-next-line:no-console | ||
console.warn("WARNING => Extension object decoding error on ", object.constructor.name, " expected size was", length, "but only this amount of bytes have been read :", stream.length - streamLengthBefore); | ||
@@ -121,0 +171,0 @@ stream.length = streamLengthBefore + length; |
@@ -0,1 +1,4 @@ | ||
/** | ||
* @module node-opcua-extension-object | ||
*/ | ||
export * from "./extension_object"; |
@@ -13,3 +13,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* @module node-opcua-extension-object | ||
*/ | ||
__exportStar(require("./extension_object"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "node-opcua-extension-object", | ||
"version": "2.6.0-alpha.7", | ||
"version": "2.6.1", | ||
"description": "pure nodejs OPCUA SDK - module -extension-object", | ||
@@ -15,8 +15,8 @@ "main": "./dist/index.js", | ||
"chalk": "^4.0.0", | ||
"node-opcua-assert": "^2.6.0-alpha.1", | ||
"node-opcua-basic-types": "^2.6.0-alpha.1", | ||
"node-opcua-binary-stream": "^2.6.0-alpha.1", | ||
"node-opcua-debug": "^2.6.0-alpha.1", | ||
"node-opcua-factory": "^2.6.0-alpha.7", | ||
"node-opcua-nodeid": "^2.6.0-alpha.1" | ||
"node-opcua-assert": "^2.6.1", | ||
"node-opcua-basic-types": "^2.6.1", | ||
"node-opcua-binary-stream": "^2.6.1", | ||
"node-opcua-debug": "^2.6.1", | ||
"node-opcua-factory": "^2.6.1", | ||
"node-opcua-nodeid": "^2.6.1" | ||
}, | ||
@@ -38,3 +38,3 @@ "author": "Etienne Rossignon", | ||
"homepage": "http://node-opcua.github.io/", | ||
"gitHead": "6af0c6f183dcb96ddc5a2befc98851d0960c5fd0" | ||
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23652
383
1
Updatednode-opcua-assert@^2.6.1
Updatednode-opcua-debug@^2.6.1
Updatednode-opcua-factory@^2.6.1
Updatednode-opcua-nodeid@^2.6.1