New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-variant

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-variant - npm Package Compare versions

Comparing version 0.5.0 to 2.0.0-alpha.2

dist/DataType_enum.d.ts

41

package.json
{
"name": "node-opcua-variant",
"version": "0.5.0",
"version": "2.0.0-alpha.2",
"description": "pure nodejs OPCUA SDK - module -variant",
"main": "index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "mocha test",
"clean": "node -e \"require('rimraf').sync('_generated_');\"",
"generate": "node ./generate"
"clean": "node -e \"require('rimraf').sync('dist');\""
},
"dependencies": {
"node-opcua-assert": "^0.5.0",
"node-opcua-basic-types": "^0.5.0",
"node-opcua-data-model": "^0.5.0",
"node-opcua-factory": "^0.5.0",
"node-opcua-nodeid": "^0.5.0",
"node-opcua-utils": "^0.5.0",
"node-opcua-assert": "^2.0.0-alpha.2",
"node-opcua-basic-types": "^2.0.0-alpha.2",
"node-opcua-data-model": "^2.0.0-alpha.2",
"node-opcua-enum": "^2.0.0-alpha.2",
"node-opcua-factory": "^2.0.0-alpha.2",
"node-opcua-nodeid": "^2.0.0-alpha.2",
"node-opcua-utils": "^2.0.0-alpha.2",
"underscore": "^1.9.1"
},
"devDependencies": {
"node-opcua-benchmarker": "^0.5.0",
"node-opcua-binary-stream": "^0.5.0",
"node-opcua-debug": "^0.5.0",
"node-opcua-generator": "^0.5.0",
"node-opcua-numeric-range": "^0.5.0",
"node-opcua-packet-analyzer": "^0.5.0",
"node-opcua-status-code": "^0.5.0",
"should": "13.2.3"
"node-opcua-benchmarker": "^2.0.0-alpha.2",
"node-opcua-binary-stream": "^2.0.0-alpha.2",
"node-opcua-debug": "^2.0.0-alpha.2",
"node-opcua-generator": "^2.0.0-alpha.2",
"node-opcua-numeric-range": "^2.0.0-alpha.2",
"node-opcua-packet-analyzer": "^2.0.0-alpha.2",
"node-opcua-status-code": "^2.0.0-alpha.2",
"should": "13.2.3",
"source-map-support": "^0.5.9"
},

@@ -45,3 +48,3 @@ "author": "Etienne Rossignon",

"homepage": "http://node-opcua.github.io/",
"gitHead": "7c2f2dcb6ebdc49e57da1a028406a307df502d4e"
"gitHead": "7f57dd90e9d8bd1abcb8d330b3470999ac51e33f"
}

@@ -15,3 +15,3 @@

const ec = require("node-opcua-basic-types");
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;
const makeExpandedNodeId = require("node-opcua-nodeid").makeExpandedNodeId;
const generate_new_id = require("node-opcua-factory").generate_new_id;

@@ -132,4 +132,4 @@ const _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;

};
Variant.prototype.decode_debug = function (stream, options) {
schema.decode_debug(this, stream, options);
Variant.prototype.decodeDebug = function (stream, options) {
schema.decodeDebug(this, stream, options);
};

@@ -136,0 +136,0 @@ /**

@@ -9,9 +9,7 @@

const _ = require("underscore");
const schema_helpers = require("node-opcua-factory/src/factories_schema_helpers");
const resolve_schema_field_types = schema_helpers.resolve_schema_field_types;
const initialize_field = schema_helpers.initialize_field;
const check_options_correctness_against_schema = schema_helpers.check_options_correctness_against_schema;
const _defaultTypeMap = require("node-opcua-factory/src/factories_builtin_types")._defaultTypeMap;
const ec = require("node-opcua-basic-types");
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;
const resolve_schema_field_types = require("node-opcua-factory").resolve_schema_field_types;
const initialize_field = require("node-opcua-factory").initialize_field;
const check_options_correctness_against_schema = require("node-opcua-factory").check_options_correctness_against_schema;
const makeExpandedNodeId = require("node-opcua-nodeid").makeExpandedNodeId;
const generate_new_id = require("node-opcua-factory").generate_new_id;

@@ -141,4 +139,4 @@ const _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;

};
Variant.prototype.decode_debug = function (stream, options) {
schema.decode_debug(this, stream, options);
Variant.prototype.decodeDebug = function (stream, options) {
schema.decodeDebug(this, stream, options);
};

@@ -145,0 +143,0 @@ /**

@@ -15,3 +15,3 @@

const ec = require("node-opcua-basic-types");
const makeExpandedNodeId = require("node-opcua-nodeid/src/expanded_nodeid").makeExpandedNodeId;
const makeExpandedNodeId = require("node-opcua-nodeid").makeExpandedNodeId;
const generate_new_id = require("node-opcua-factory").generate_new_id;

@@ -145,4 +145,4 @@ const _enumerations = require("node-opcua-factory/src/factories_enumerations")._private._enumerations;

};
Variant.prototype.decode_debug = function (stream, options) {
schema.decode_debug(this, stream, options);
Variant.prototype.decodeDebug = function (stream, options) {
schema.decodeDebug(this, stream, options);
};

@@ -149,0 +149,0 @@ /**

@@ -1,112 +0,112 @@

"use strict";
const Benchmarker = require("node-opcua-benchmarker").Benchmarker;
const should = require("should");
const DataType = require("..").DataType;
const Variant = require("..").Variant;
const Variant1 = require("./data_factory_code_generator/_auto_generated_Variant_Gen1").Variant;
const Variant2 = require("./data_factory_code_generator/_auto_generated_Variant_Gen2").Variant;
const Variant3 = require("./data_factory_code_generator/_auto_generated_Variant_Gen3").Variant;
describe("Benchmarking Factory Implementation", function (done) {
function test_variant(VariantX) {
const variant = new VariantX({
dataType: DataType.Double,
value: 24
});
variant.dataType.should.eql(DataType.Double);
if (variant.setDataType) {
variant.setDataType(DataType.Variant);
} else {
variant.dataType = DataType.Variant.value;
}
variant.dataType.should.eql(DataType.Variant);
should(function () {
if (variant.setDataType) {
// new version uses the set<EnumType> helper function
variant.setDataType(34);
} else {
variant.dataType = 34;
}
}).throw();
const variant2 = new VariantX(variant);
(variant.hasOwnProperty("dataType") ||
VariantX.prototype.hasOwnProperty("dataType")).should.eql(true);
const variant3 = new VariantX(variant);
variant3.dataType.should.eql(variant.dataType);
variant3.arrayType.should.eql(variant.arrayType);
variant3.value.should.eql(variant.value);
}
it("Variant1 should work as expected", function (done) {
test_variant(Variant1);
done();
});
it("Variant2 should work as expected", function (done) {
test_variant(Variant2);
done();
});
it("Variant3 should work as expected", function (done) {
test_variant(Variant3);
done();
});
it("Variant should work as expected", function (done) {
test_variant(Variant);
done();
});
this.timeout(200000);
function perform_benchmark(params, checks, done) {
const bench = new Benchmarker();
function test_iteration(VARIANT) {
const variant = new VARIANT({
dataType: DataType.Double,
value: 24
});
}
bench.add("Variant1", function () {
test_iteration(Variant1);
})
.add("Variant2", function () {
test_iteration(Variant2);
})
.add("Variant3", function () {
test_iteration(Variant3);
})
.add("Variant", function () {
test_iteration(Variant);
})
.on("cycle", function (message) {
console.log(message);
})
.on("complete", function () {
console.log(" Fastest is " + this.fastest.name);
console.log(" Speed Up : x", this.speedUp);
["Variant3", "Variant"].indexOf(this.fastest.name).should.not.eql(-1);
done();
})
.run();
}
it("should", function (done) {
perform_benchmark(null, null, done);
});
});
// "use strict";
// const Benchmarker = require("node-opcua-benchmarker").Benchmarker;
// const should = require("should");
//
// const DataType = require("..").DataType;
// const Variant = require("..").Variant;
//
// const Variant1 = require("./data_factory_code_generator/_auto_generated_Variant_Gen1").Variant;
// const Variant2 = require("./data_factory_code_generator/_auto_generated_Variant_Gen2").Variant;
// const Variant3 = require("./data_factory_code_generator/_auto_generated_Variant_Gen3").Variant;
//
// describe("Benchmarking Factory Implementation", function (done) {
//
//
// function test_variant(VariantX) {
//
// const variant = new VariantX({
// dataType: DataType.Double,
// value: 24
// });
// variant.dataType.should.eql(DataType.Double);
//
// if (variant.setDataType) {
// variant.setDataType(DataType.Variant);
// } else {
// variant.dataType = DataType.Variant;
// }
// variant.dataType.should.eql(DataType.Variant);
//
// should(function () {
// if (variant.setDataType) {
// // new version uses the set<EnumType> helper function
// variant.setDataType(34);
// } else {
// variant.dataType = 34;
// }
// }).throw();
//
// const variant2 = new VariantX(variant);
//
// (variant.hasOwnProperty("dataType") ||
// VariantX.prototype.hasOwnProperty("dataType")).should.eql(true);
//
// const variant3 = new VariantX(variant);
//
// variant3.dataType.should.eql(variant.dataType);
// variant3.arrayType.should.eql(variant.arrayType);
// variant3.value.should.eql(variant.value);
//
// }
//
// it("Variant1 should work as expected", function (done) {
// test_variant(Variant1);
// done();
// });
// it("Variant2 should work as expected", function (done) {
// test_variant(Variant2);
// done();
// });
// it("Variant3 should work as expected", function (done) {
// test_variant(Variant3);
// done();
// });
// it("Variant should work as expected", function (done) {
// test_variant(Variant);
// done();
// });
//
// this.timeout(200000);
// function perform_benchmark(params, checks, done) {
//
// const bench = new Benchmarker();
//
//
// function test_iteration(VARIANT) {
// const variant = new VARIANT({
// dataType: DataType.Double,
// value: 24
// });
// }
//
// bench.add("Variant1", function () {
// test_iteration(Variant1);
// })
// .add("Variant2", function () {
// test_iteration(Variant2);
// })
// .add("Variant3", function () {
// test_iteration(Variant3);
// })
// .add("Variant", function () {
// test_iteration(Variant);
// })
// .on("cycle", function (message) {
// console.log(message);
// })
// .on("complete", function () {
//
// console.log(" Fastest is " + this.fastest.name);
// console.log(" Speed Up : x", this.speedUp);
// ["Variant3", "Variant"].indexOf(this.fastest.name).should.not.eql(-1);
// done();
// })
// .run();
//
// }
//
// it("should", function (done) {
// perform_benchmark(null, null, done);
// });
//
// });

@@ -14,3 +14,3 @@ "use strict";

const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/test_helpers/encode_decode_round_trip_test")
const encode_decode_round_trip_test = require("node-opcua-packet-analyzer/dist/test_helpers")
.encode_decode_round_trip_test;

@@ -23,5 +23,4 @@

const Variant_ArrayMask = 0x80;
const Variant_ArrayDimensionsMask = 0x40;
const Variant_TypeMask = 0x3f;
const VARIANT_ARRAY_MASK = require("..").VARIANT_ARRAY_MASK;
const VARIANT_ARRAY_DIMENSIONS_MASK = require("..").VARIANT_ARRAY_DIMENSIONS_MASK;

@@ -33,4 +32,4 @@ const factories = require("node-opcua-factory");

describe("Variant", function() {
it("should create a empty Variant", function() {
describe("Variant", function () {
it("should create a empty Variant", function () {
const var1 = new Variant();

@@ -43,3 +42,3 @@

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(1);

@@ -49,4 +48,4 @@ });

it("should create a Scalar UInt32 Variant", function() {
const var1 = new Variant({ dataType: DataType.UInt32, value: 10 });
it("should create a Scalar UInt32 Variant", function () {
const var1 = new Variant({dataType: DataType.UInt32, value: 10});

@@ -56,3 +55,3 @@ var1.dataType.should.eql(DataType.UInt32);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5);

@@ -62,4 +61,4 @@ });

it("should create a Scalar UInt64 Variant", function() {
const var1 = new Variant({ arrayType: VariantArrayType.Scalar, dataType: DataType.UInt64, value: [10, 20] });
it("should create a Scalar UInt64 Variant", function () {
const var1 = new Variant({arrayType: VariantArrayType.Scalar, dataType: DataType.UInt64, value: [10, 20]});

@@ -69,3 +68,3 @@ var1.dataType.should.eql(DataType.UInt64);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(9);

@@ -75,6 +74,7 @@ });

it("should create a Scalar LocalizedText Variant 1/2", function() {
it("should create a Scalar LocalizedText Variant 1/2", function () {
const var1 = new Variant({
dataType: DataType.LocalizedText,
value: new LocalizedText({ text: "Hello", locale: "en" })
value: new LocalizedText({text: "Hello", locale: "en"})
});

@@ -85,5 +85,5 @@

var1.value._schema.name.should.equal("LocalizedText");
var1.value.schema.name.should.equal("LocalizedText");
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(17);

@@ -93,6 +93,6 @@ });

it("should create a Scalar LocalizedText Variant 2/2", function() {
it("should create a Scalar LocalizedText Variant 2/2", function () {
const var1 = new Variant({
dataType: DataType.LocalizedText,
value: { text: "Hello", locale: "en" }
value: {text: "Hello", locale: "en"}
});

@@ -103,5 +103,5 @@

var1.value._schema.name.should.equal("LocalizedText");
var1.value.schema.name.should.equal("LocalizedText");
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(17);

@@ -111,6 +111,7 @@ });

it("should create a Scalar QualifiedName Variant 1/2", function() {
it("should create a Scalar QualifiedName Variant 1/2", function () {
const var1 = new Variant({
dataType: DataType.QualifiedName,
value: new QualifiedName({ name: "Hello", namespaceIndex: 0 })
value: new QualifiedName({name: "Hello", namespaceIndex: 0})
});

@@ -120,5 +121,6 @@

var1.arrayType.should.eql(VariantArrayType.Scalar);
var1.value._schema.name.should.equal("QualifiedName");
var1.value.schema.name.should.equal("QualifiedName");
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
// ETIENNE 26/07/2018
stream.length.should.equal(12);

@@ -128,6 +130,6 @@ });

it("should create a Scalar QualifiedName Variant 2/2", function() {
it("should create a Scalar QualifiedName Variant 2/2", function () {
const var1 = new Variant({
dataType: DataType.QualifiedName,
value: { name: "Hello", namespaceIndex: 0 }
value: {name: "Hello", namespaceIndex: 0}
});

@@ -138,5 +140,6 @@

var1.value._schema.name.should.equal("QualifiedName");
var1.value.schema.name.should.equal("QualifiedName");
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
// ETIENNE 26/07/2018
stream.length.should.equal(12);

@@ -146,4 +149,4 @@ });

it("should create a Scalar ByteString Variant - null", function() {
const var1 = new Variant({ dataType: DataType.ByteString, value: null });
it("should create a Scalar ByteString Variant - null", function () {
const var1 = new Variant({dataType: DataType.ByteString, value: null});

@@ -153,3 +156,3 @@ var1.dataType.should.eql(DataType.ByteString);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5);

@@ -159,4 +162,4 @@ });

it("should create a Scalar ByteString Variant - empty buffer", function() {
const var1 = new Variant({ dataType: DataType.ByteString, value: Buffer.alloc(0) });
it("should create a Scalar ByteString Variant - empty buffer", function () {
const var1 = new Variant({dataType: DataType.ByteString, value: Buffer.alloc(0)});

@@ -166,3 +169,3 @@ var1.dataType.should.eql(DataType.ByteString);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5);

@@ -172,4 +175,4 @@ });

it("should create a Scalar ByteString Variant - 3 bytes", function() {
const var1 = new Variant({ dataType: DataType.ByteString, value: Buffer.from("ABC") });
it("should create a Scalar ByteString Variant - 3 bytes", function () {
const var1 = new Variant({dataType: DataType.ByteString, value: Buffer.from("ABC")});

@@ -179,3 +182,3 @@ var1.dataType.should.eql(DataType.ByteString);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5 + 3);

@@ -185,4 +188,4 @@ });

it("should create a Scalar String Variant", function() {
const var1 = new Variant({ dataType: DataType.String, value: "Hello" });
it("should create a Scalar String Variant", function () {
const var1 = new Variant({dataType: DataType.String, value: "Hello"});

@@ -192,3 +195,3 @@ var1.dataType.should.eql(DataType.String);

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(1 + 4 + 5);

@@ -198,3 +201,3 @@ });

it("should create a Array String Variant", function() {
it("should create a Array String Variant", function () {
const var1 = new Variant({

@@ -212,3 +215,3 @@ dataType: DataType.String,

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(1 + 4 + (4 + 5 + 4 + 5));

@@ -218,7 +221,7 @@ });

it("should create a Array QualifiedName Variant", function() {
it("should create a Array QualifiedName Variant", function () {
const var1 = new Variant({
dataType: DataType.QualifiedName,
arrayType: VariantArrayType.Array,
value: [{ name: "Hello", namespaceIndex: 0 }, { name: "World", namespaceIndex: 0 }]
value: [{name: "Hello", namespaceIndex: 0}, {name: "World", namespaceIndex: 0}]
});

@@ -229,5 +232,5 @@

var1.value[0]._schema.name.should.equal("QualifiedName");
var1.value[0].schema.name.should.equal("QualifiedName");
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(27);

@@ -237,3 +240,3 @@ });

it("should create a Array of GUID Variant", function() {
it("should create a Array of GUID Variant", function () {
const var1 = new Variant({

@@ -250,3 +253,3 @@ dataType: DataType.Guid,

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(101);

@@ -256,3 +259,3 @@ });

it("should detect invalid SByte Variant", function() {
it("should detect invalid SByte Variant", function () {
const var1 = new Variant({

@@ -267,3 +270,3 @@ dataType: DataType.SByte,

it("should detect invalid Array<Int32> Variant", function() {
it("should detect invalid Array<Int32> Variant", function () {
const var1 = new Variant({

@@ -286,3 +289,3 @@ dataType: DataType.UInt32,

it("should create a Variant as a Matrix (2x3) of UInt32 - Matrix given as a flat array", function() {
it("should create a Variant as a Matrix (2x3) of UInt32 - Matrix given as a flat array", function () {
const var1 = new Variant({

@@ -300,3 +303,3 @@ dataType: DataType.UInt32,

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
// 1 encoding byte 1

@@ -315,3 +318,3 @@ // 1 UInt32 => ArrayLength 4

xit("not supported - should create a Variant as a Matrix (2x3) of UInt32 - Matrix given as a Array of Array", function() {
xit("not supported - should create a Variant as a Matrix (2x3) of UInt32 - Matrix given as a Array of Array", function () {
const var1 = new Variant({

@@ -321,3 +324,3 @@ dataType: DataType.UInt32,

dimensions: [2, 3],
value: [ [ 0x000, 0x001, 0x002], [0x010, 0x011, 0x012]]
value: [[0x000, 0x001, 0x002], [0x010, 0x011, 0x012]]
});

@@ -332,3 +335,3 @@

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
// 1 encoding byte 1

@@ -347,3 +350,3 @@ // 1 UInt32 => ArrayLength 4

it("should raise an exception when construction a Matrix with incorrect element size", function() {
it("should raise an exception when construction a Matrix with incorrect element size", function () {
should(function construct_matrix_variant_with_invalid_value() {

@@ -359,13 +362,17 @@ const var1 = new Variant({

it("should create a Array ByteString Variant ", function() {
const var1 = new Variant({ dataType: DataType.ByteString, value: [Buffer.from("ABC"), null] });
it("should create a Array of ByteString Variant ", function () {
const var1 = new Variant({
dataType: DataType.ByteString,
value: [Buffer.from("ABC"), null]
});
var1.dataType.should.eql(DataType.ByteString);
var1.arrayType.should.eql(VariantArrayType.Array);
encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5 + 4 + 3 + 4);
});
});
it("should create a Array UInt64 Variant", function() {
it("should create a Array UInt64 Variant", function () {
const var1 = new Variant({

@@ -380,3 +387,3 @@ arrayType: VariantArrayType.Array,

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(5 + 8 + 8);

@@ -386,3 +393,3 @@ });

it("should create a Array of ByteString Variant", function() {
it("should create a Array of ByteString Variant", function () {
const value = [Buffer.from("ABCD"), null];

@@ -399,3 +406,3 @@

encode_decode_round_trip_test(var1, function(stream) {
encode_decode_round_trip_test(var1, function (stream) {
stream.length.should.equal(17);

@@ -409,3 +416,3 @@ });

describe("Variant - Analyser", function() {
describe("Variant - Analyser", function () {
// increase timeout to cope with istanbul

@@ -424,16 +431,16 @@ this.timeout(Math.max(400000, this._timeout));

const various_variants = [
new Variant({ dataType: DataType.NodeId, arrayType: VariantArrayType.Scalar, value: makeNodeId(1, 2) }),
new Variant({dataType: DataType.NodeId, arrayType: VariantArrayType.Scalar, value: makeNodeId(1, 2)}),
new Variant({
dataType: DataType.LocalizedText,
arrayType: VariantArrayType.Scalar,
value: new LocalizedText({ text: "Hello", locale: "en" })
value: new LocalizedText({text: "Hello", locale: "en"})
}),
new Variant({ dataType: DataType.Double, arrayType: VariantArrayType.Scalar, value: 3.14 }),
new Variant({ dataType: DataType.Guid, arrayType: VariantArrayType.Scalar, value: ec.randomGuid() }),
new Variant({dataType: DataType.Double, arrayType: VariantArrayType.Scalar, value: 3.14}),
new Variant({dataType: DataType.Guid, arrayType: VariantArrayType.Scalar, value: ec.randomGuid()}),
// various Variant Array
new Variant({ dataType: DataType.Int32, arrayType: VariantArrayType.Array /*, unspecified value*/ }),
new Variant({ dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: [] }),
new Variant({ dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array([1]) }),
new Variant({ dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array([1, 2]) }),
new Variant({dataType: DataType.Int32, arrayType: VariantArrayType.Array /*, unspecified value*/}),
new Variant({dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: []}),
new Variant({dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array([1])}),
new Variant({dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array([1, 2])}),
new Variant({

@@ -454,4 +461,4 @@ dataType: DataType.UInt32,

}),
new Variant({ dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array(manyValues) }),
new Variant({ dataType: DataType.Double, arrayType: VariantArrayType.Array, value: veryLargeFloatArray }),
new Variant({dataType: DataType.Int32, arrayType: VariantArrayType.Array, value: new Int32Array(manyValues)}),
new Variant({dataType: DataType.Double, arrayType: VariantArrayType.Array, value: veryLargeFloatArray}),

@@ -475,5 +482,5 @@ // variant Matrix

it("should analyze variant", function() {
redirectToFile("variant_analyze1.log", function() {
various_variants.forEach(function(v) {
it("should analyze variant", function () {
redirectToFile("variant_analyze1.log", function () {
various_variants.forEach(function (v) {
analyze_object_binary_encoding(v);

@@ -483,11 +490,27 @@ });

});
it("should encode/decode variant", function() {
various_variants.forEach(function(v, index) {
encode_decode_round_trip_test(v, function(stream) {
// stream.length.should.equal(1+4+4*4);
it("ZZ1 should encode/decode variant", function () {
const v = new Variant({
dataType: DataType.Int32,
arrayType: VariantArrayType.Matrix,
value: [1, 2, 3, 4, 5, 6],
dimensions: [2, 3]
});
encode_decode_round_trip_test(v, (stream) => {
// stream.length.should.equal(1+4+4*4);
});
});
it("should encode/decode a very large array of Float - 1", function() {
it("should encode/decode variant", function () {
for (const v of various_variants) {
encode_decode_round_trip_test(v, (stream) => {
// stream.length.should.equal(1+4+4*4);
});
}
});
it("should encode/decode a very large array of Float - 1", function () {
const get_clock_tick = require("node-opcua-utils").get_clock_tick;

@@ -524,3 +547,3 @@

it("should encode/decode a very large array of Float", function() {
it("should encode/decode a very large array of Float", function () {
const nbElements = 1500 * 1024;

@@ -536,3 +559,3 @@ const very_large = new Variant({

}
encode_decode_round_trip_test(very_large, function(stream) {
encode_decode_round_trip_test(very_large, function (stream) {
// stream.length.should.equal(1+4+4*4);

@@ -542,3 +565,3 @@ });

it("should check the performance of encode/decode a very large array of Float", function() {
it("should check the performance of encode/decode a very large array of Float", function () {
this.timeout(Math.max(300000, this._timeout));

@@ -569,14 +592,14 @@

bench
.add("Variant.encode", function() {
.add("Variant.encode", function () {
stream.rewind();
obj.encode(stream);
})
.add("Variant.decode", function() {
.add("Variant.decode", function () {
stream.rewind();
obj_reloaded.decode(stream);
})
.on("cycle", function(message) {
.on("cycle", function (message) {
//xx console.log(message);
})
.on("complete", function() {
.on("complete", function () {
console.log(" Fastest is " + this.fastest.name);

@@ -586,3 +609,3 @@ console.log(" Speed Up : x", this.speedUp);

})
.run({ max_time: 0.2 });
.run({max_time: 0.2});

@@ -604,3 +627,3 @@ // note : the following test could be *slow* with large value of length

const old_encode = function(variant, stream) {
const old_encode = function (variant, stream) {
// NOTE: this code matches the old implement and should not be changed

@@ -614,9 +637,9 @@ // It is useful to compare new performance of the encode method

if (variant.arrayType === VariantArrayType.Array) {
encodingByte |= Variant_ArrayMask;
encodingByte |= VARIANT_ARRAY_MASK;
}
ec.encodeUInt8(encodingByte, stream);
const encode = factories.findBuiltInType(variant.dataType.key).encode;
const encode = factories.findBuiltInType(DataType[variant.dataType]).encode;
/* istanbul ignore next */
if (!encode) {
throw new Error("Cannot find encode function for dataType " + variant.dataType.key);
throw new Error("Cannot find encode function for dataType " + DataType[variant.dataType]);
}

@@ -626,3 +649,3 @@ if (variant.arrayType === VariantArrayType.Array) {

ec.encodeUInt32(arr.length, stream);
arr.forEach(function(el) {
arr.forEach(function (el) {
encode(el, stream);

@@ -635,3 +658,3 @@ });

describe("benchmarking variant encode", function() {
xdescribe("benchmarking variant encode", function () {
function perform_benchmark(done) {

@@ -645,2 +668,4 @@ const bench = new Benchmarker();

const encodeVariant = require("..").encodeVariant;
var stream = new BinaryStream(4096);

@@ -1133,26 +1158,24 @@ const variant = new Variant({

bench
.add("Variant.encode", function() {
assert(_.isFunction(Variant.prototype._schema.encode));
test_iteration(variant, stream, Variant.prototype._schema.encode);
.add("Variant.encode", function () {
assert(_.isFunction(encodeVariant));
test_iteration(variant, stream, encodeVariant);
})
.add("Variant.old_encode", function() {
.add("Variant.old_encode", function () {
assert(_.isFunction(old_encode));
test_iteration(variant, stream, old_encode);
})
.on("cycle", function(message) {
.on("cycle", function (message) {
// console.log(message);
})
.on("complete", function() {
.on("complete", function () {
console.log(" Fastest is " + this.fastest.name);
console.log(" Speed Up : x", this.speedUp);
// this test fails only on AppVeyor ! why ?
//xx this.fastest.name.should.eql("Variant.encode");
done();
})
.run({ max_time: 0.1 });
.run({max_time: 0.1});
}
it("should verify that current Variant.encode method is better than old implementation", function(done) {
it("should verify that current Variant.encode method is better than old implementation", function (done) {
perform_benchmark(done);

@@ -1162,3 +1185,3 @@ });

describe("benchmarking float Array encode/decode", function() {
describe("benchmarking float Array encode/decode", function () {
this.timeout(Math.max(200000, this._timeout));

@@ -1205,3 +1228,3 @@

for (let i = 0; i < n; i++) {
stream._buffer[stream.length++] = byteArr[i];
stream.buffer[stream.length++] = byteArr[i];
}

@@ -1238,6 +1261,6 @@ }

stream.rewind();
const r = [test_1, test_2, test_3, test_4, test_5, test_6].map(function(fct) {
const r = [test_1, test_2, test_3, test_4, test_5, test_6].map(function (fct) {
stream.rewind();
fct(stream, variant.value);
const reference_buf = stream._buffer.slice(0, stream._buffer.length);
const reference_buf = stream.buffer.slice(0, stream.buffer.length);
return reference_buf.toString("hex");

@@ -1252,24 +1275,24 @@ });

bench
.add("test1", function() {
.add("test1", function () {
test_iteration(variant, stream, test_1);
})
.add("test2", function() {
.add("test2", function () {
test_iteration(variant, stream, test_2);
})
.add("test3", function() {
.add("test3", function () {
test_iteration(variant, stream, test_3);
})
.add("test4", function() {
.add("test4", function () {
test_iteration(variant, stream, test_4);
})
.add("test5", function() {
.add("test5", function () {
test_iteration(variant, stream, test_5);
})
.add("test6", function() {
.add("test6", function () {
test_iteration(variant, stream, test_6);
})
.on("cycle", function(message) {
.on("cycle", function (message) {
//xx console.log(message);
})
.on("complete", function() {
.on("complete", function () {
console.log(" slowest is " + this.slowest.name);

@@ -1281,6 +1304,6 @@ console.log(" Fastest is " + this.fastest.name);

})
.run({ max_time: 0.1 });
.run({max_time: 0.1});
}
it("should check which is the faster way to encode decode a float", function(done) {
it("should check which is the faster way to encode decode a float", function (done) {
perform_benchmark(done);

@@ -1290,4 +1313,5 @@ });

describe("Variant with Advanced Array", function() {
it("should automatically detect that variant is an array when ArrayType is missing ", function() {
describe("Variant with Advanced Array", function () {
it("should automatically detect that variant is an array when ArrayType is missing ", function () {
const v = new Variant({

@@ -1301,3 +1325,5 @@ dataType: "Float",

encode_decode_round_trip_test(v, function(stream) {
v.value.should.be.instanceOf(Float32Array);
encode_decode_round_trip_test(v, function (stream) {
stream.length.should.equal(1 + 4 + 2 * 4);

@@ -1307,3 +1333,3 @@ });

it("should be possible to handle an Float array with a Float32Array", function() {
it("should be possible to handle an Float array with a Float32Array", function () {
const v = new Variant({

@@ -1314,3 +1340,3 @@ dataType: DataType.Float,

});
encode_decode_round_trip_test(v, function(stream) {
encode_decode_round_trip_test(v, function (stream) {
stream.length.should.equal(1 + 4 + 4 * 4);

@@ -1320,3 +1346,3 @@ });

it("should be possible to encode/decode an subarray of Float32Array", function() {
it("should be possible to encode/decode an subarray of Float32Array", function () {
const v = new Variant({

@@ -1333,3 +1359,3 @@ dataType: DataType.Float,

v.value[1].should.eql(4);
encode_decode_round_trip_test(v, function(stream) {
encode_decode_round_trip_test(v, function (stream) {
stream.length.should.equal(1 + 4 + 4 + 4);

@@ -1339,3 +1365,3 @@ });

it("should be possible to read a sub matrix of a array of byte strings", function() {
it("should be possible to read a sub matrix of a array of byte strings", function () {
const v = new Variant({

@@ -1357,3 +1383,3 @@ dataType: DataType.ByteString,

it("AA should be possible to read a sub matrix of a matrix of double", function() {
it("AA should be possible to read a sub matrix of a matrix of double", function () {
const v = new Variant({

@@ -1400,11 +1426,12 @@ dataType: DataType.Double,

describe("Variant with enumeration", function() {
describe("Variant with enumeration", function () {
const SomeEnum = DataType;
before(function() {
before(function () {
should.exist(SomeEnum.DiagnosticInfo);
});
it("should fail to create a variant from a enumeration item if dataType is not Int32", function() {
should(function() {
it("should fail to create a variant from a enumeration item if dataType is not Int32", function () {
should(function () {
const v = new Variant({

@@ -1418,3 +1445,3 @@ dataType: DataType.UInt32,

it("should create a variant from a enumeration item", function() {
it("should create a variant from a enumeration item", function () {
should.exist(SomeEnum.DiagnosticInfo);

@@ -1426,6 +1453,6 @@ const v = new Variant({

// console.log(v.toString());
v.value.should.eql(SomeEnum.DiagnosticInfo.value);
v.value.should.eql(SomeEnum.DiagnosticInfo);
});
xit("should not be necessary to specify the dataType for a variant containing enumeration item", function() {
xit("should not be necessary to specify the dataType for a variant containing enumeration item", function () {
const v = new Variant({

@@ -1439,3 +1466,3 @@ value: SomeEnum.DiagnosticInfo

it("should create a variant with builtin type 'Duration'", function() {
it("should create a variant with builtin type 'Duration'", function () {
const v = new Variant({

@@ -1448,3 +1475,3 @@ dataType: "Duration",

});
it("should create a variant with builtin type 'ByteString'", function() {
it("should create a variant with builtin type 'ByteString'", function () {
const v = new Variant({

@@ -1457,3 +1484,3 @@ dataType: "ByteString",

});
it("should create a variant copy (with it's own array) ", function() {
it("should create a variant copy (with it's own array) ", function () {
const options = {

@@ -1525,7 +1552,7 @@ dataType: DataType.Float,

const sameVariantSlow = function(v1, v2) {
const sameVariantSlow = function (v1, v2) {
return _.isEqual(v1, v2);
};
describe("testing sameVariant Performance", function() {
describe("testing sameVariant Performance", function () {
this.timeout(40000);

@@ -1545,17 +1572,17 @@

const a = [
new Variant({ dataType: DataType.String, arrayType: VariantArrayType.Array, value: null }),
new Variant({ dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: null }),
new Variant({ dataType: DataType.String, value: "Hello" }),
new Variant({ dataType: DataType.String, value: "HelloWorld" }),
new Variant({ dataType: DataType.Double, value: 42.0 }),
new Variant({ dataType: DataType.Float, value: 42.0 }),
new Variant({ dataType: DataType.Int32, value: 42 }),
new Variant({ dataType: DataType.UInt32, value: 42 }),
new Variant({ dataType: DataType.Double, value: 43.0 }),
new Variant({ dataType: DataType.Float, value: 43.0 }),
new Variant({ dataType: DataType.Int32, value: 43 }),
new Variant({ dataType: DataType.UInt32, value: 43 }),
new Variant({ dataType: DataType.UInt64, value: [43, 100], arrayType: VariantArrayType.Scalar }),
new Variant({ dataType: DataType.Int64, value: [43, 1000], arrayType: VariantArrayType.Scalar }),
new Variant({ dataType: DataType.String, arrayType: VariantArrayType.Array, value: ["Hello", "World"] }),
new Variant({dataType: DataType.String, arrayType: VariantArrayType.Array, value: null}),
new Variant({dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: null}),
new Variant({dataType: DataType.String, value: "Hello"}),
new Variant({dataType: DataType.String, value: "HelloWorld"}),
new Variant({dataType: DataType.Double, value: 42.0}),
new Variant({dataType: DataType.Float, value: 42.0}),
new Variant({dataType: DataType.Int32, value: 42}),
new Variant({dataType: DataType.UInt32, value: 42}),
new Variant({dataType: DataType.Double, value: 43.0}),
new Variant({dataType: DataType.Float, value: 43.0}),
new Variant({dataType: DataType.Int32, value: 43}),
new Variant({dataType: DataType.UInt32, value: 43}),
new Variant({dataType: DataType.UInt64, value: [43, 100], arrayType: VariantArrayType.Scalar}),
new Variant({dataType: DataType.Int64, value: [43, 1000], arrayType: VariantArrayType.Scalar}),
new Variant({dataType: DataType.String, arrayType: VariantArrayType.Array, value: ["Hello", "World"]}),
new Variant({

@@ -1669,7 +1696,7 @@ dataType: DataType.Double,

it("sameVariant should be very efficient ", function() {
it("sameVariant should be very efficient ", function () {
const bench = new Benchmarker();
bench
.add("fast sameVariant", function() {
.add("fast sameVariant", function () {
for (let i = 0; i < variousVariants.length; i++) {

@@ -1681,3 +1708,3 @@ for (let j = 0; j < variousVariants.length; j++) {

})
.add("slow sameVariant", function() {
.add("slow sameVariant", function () {
for (let i = 0; i < variousVariants.length; i++) {

@@ -1689,6 +1716,6 @@ for (let j = 0; j < variousVariants.length; j++) {

})
.on("cycle", function(message) {
.on("cycle", function (message) {
console.log(message);
})
.on("complete", function() {
.on("complete", function () {
console.log(" Fastest is " + this.fastest.name);

@@ -1700,7 +1727,7 @@ console.log(" Speed Up : x", this.speedUp);

})
.run({ max_time: 1 /*second */ });
.run({max_time: 1 /*second */});
});
});
describe("testing variant Clone & Copy Construct", function() {
describe("testing variant Clone & Copy Construct", function () {
function SomeExtensionObject(options) {

@@ -1719,3 +1746,3 @@ this.a = options.a;

function install_test(copy_construct_or_clone, copy_construct_or_clone_func) {
it("should " + copy_construct_or_clone + " a simple variant", function() {
it("should " + copy_construct_or_clone + " a simple variant", function () {
const v = new Variant({

@@ -1731,3 +1758,3 @@ dataType: DataType.UInt32,

});
it("should " + copy_construct_or_clone + " a variant array", function() {
it("should " + copy_construct_or_clone + " a variant array", function () {
const v = new Variant({

@@ -1751,4 +1778,4 @@ dataType: DataType.UInt32,

});
it("should " + copy_construct_or_clone + " a variant containing a extension object", function() {
const extObj = new SomeExtensionObject({ a: 36 });
it("should " + copy_construct_or_clone + " a variant containing a extension object", function () {
const extObj = new SomeExtensionObject({a: 36});
const v = new Variant({

@@ -1771,5 +1798,5 @@ dataType: DataType.ExtensionObject,

});
it("should " + copy_construct_or_clone + " a variant containing a extension object array", function() {
const extObj1 = new SomeExtensionObject({ a: 36 });
const extObj2 = new SomeExtensionObject({ a: 37 });
it("should " + copy_construct_or_clone + " a variant containing a extension object array", function () {
const extObj1 = new SomeExtensionObject({a: 36});
const extObj2 = new SomeExtensionObject({a: 37});
const v = new Variant({

@@ -1823,3 +1850,3 @@ dataType: DataType.ExtensionObject,

console.log(JSON.parse(jsonStr));
// console.log(JSON.parse(jsonStr));

@@ -1832,3 +1859,3 @@ const b2 = new Variant(JSON.parse(jsonStr));

});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc