node-opcua-json 0.50.0 → 2.182.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +141 -4
- package/dist/decode_opcua_json.d.ts +31 -0
- package/dist/decode_opcua_json.js +61 -0
- package/dist/decode_opcua_json.js.map +1 -0
- package/dist/extension_object_constructor.d.ts +46 -0
- package/dist/extension_object_constructor.js +26 -0
- package/dist/extension_object_constructor.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/json_basic_encoding_body_functor.d.ts +34 -0
- package/dist/json_basic_encoding_body_functor.js +170 -0
- package/dist/json_basic_encoding_body_functor.js.map +1 -0
- package/dist/json_basic_encoding_decoding_byte_string.d.ts +27 -0
- package/dist/json_basic_encoding_decoding_byte_string.js +27 -0
- package/dist/json_basic_encoding_decoding_byte_string.js.map +1 -0
- package/dist/json_basic_encoding_decoding_data_value.d.ts +80 -0
- package/dist/json_basic_encoding_decoding_data_value.js +289 -0
- package/dist/json_basic_encoding_decoding_data_value.js.map +1 -0
- package/dist/json_basic_encoding_decoding_date_time.d.ts +26 -0
- package/dist/json_basic_encoding_decoding_date_time.js +43 -0
- package/dist/json_basic_encoding_decoding_date_time.js.map +1 -0
- package/dist/json_basic_encoding_decoding_extension_object.d.ts +65 -0
- package/dist/json_basic_encoding_decoding_extension_object.js +461 -0
- package/dist/json_basic_encoding_decoding_extension_object.js.map +1 -0
- package/dist/json_basic_encoding_decoding_int64.d.ts +30 -0
- package/dist/json_basic_encoding_decoding_int64.js +56 -0
- package/dist/json_basic_encoding_decoding_int64.js.map +1 -0
- package/dist/json_basic_encoding_decoding_localizedtext.d.ts +33 -0
- package/dist/json_basic_encoding_decoding_localizedtext.js +62 -0
- package/dist/json_basic_encoding_decoding_localizedtext.js.map +1 -0
- package/dist/json_basic_encoding_decoding_nodeid.d.ts +42 -0
- package/dist/json_basic_encoding_decoding_nodeid.js +298 -0
- package/dist/json_basic_encoding_decoding_nodeid.js.map +1 -0
- package/dist/json_basic_encoding_decoding_qualifiedname.d.ts +35 -0
- package/dist/json_basic_encoding_decoding_qualifiedname.js +126 -0
- package/dist/json_basic_encoding_decoding_qualifiedname.js.map +1 -0
- package/dist/json_basic_encoding_decoding_statuscode.d.ts +39 -0
- package/dist/json_basic_encoding_decoding_statuscode.js +139 -0
- package/dist/json_basic_encoding_decoding_statuscode.js.map +1 -0
- package/dist/json_basic_encoding_decoding_variant.d.ts +101 -0
- package/dist/json_basic_encoding_decoding_variant.js +234 -0
- package/dist/json_basic_encoding_decoding_variant.js.map +1 -0
- package/dist/json_encoding_scheme.d.ts +50 -0
- package/dist/json_encoding_scheme.js +117 -0
- package/dist/json_encoding_scheme.js.map +1 -0
- package/package.json +57 -35
- package/source/decode_opcua_json.ts +67 -0
- package/source/extension_object_constructor.ts +48 -0
- package/source/index.ts +59 -0
- package/source/json_basic_encoding_body_functor.ts +190 -0
- package/source/json_basic_encoding_decoding_byte_string.ts +52 -0
- package/source/json_basic_encoding_decoding_data_value.ts +392 -0
- package/source/json_basic_encoding_decoding_date_time.ts +42 -0
- package/source/json_basic_encoding_decoding_extension_object.ts +531 -0
- package/source/json_basic_encoding_decoding_int64.ts +74 -0
- package/source/json_basic_encoding_decoding_localizedtext.ts +69 -0
- package/source/json_basic_encoding_decoding_nodeid.ts +356 -0
- package/source/json_basic_encoding_decoding_qualifiedname.ts +144 -0
- package/source/json_basic_encoding_decoding_statuscode.ts +151 -0
- package/source/json_basic_encoding_decoding_variant.ts +339 -0
- package/source/json_encoding_scheme.ts +114 -0
- package/LICENSE.md +0 -40
- package/dist2/decode_opcua_json.d.ts +0 -12
- package/dist2/index.d.ts +0 -17
- package/dist2/index.js +0 -1
- package/dist2/json_basic_encoding_body_functor.d.ts +0 -14
- package/dist2/json_basic_encoding_decoding_byte_string.d.ts +0 -8
- package/dist2/json_basic_encoding_decoding_data_value.d.ts +0 -26
- package/dist2/json_basic_encoding_decoding_date_time.d.ts +0 -6
- package/dist2/json_basic_encoding_decoding_extension_object.d.ts +0 -32
- package/dist2/json_basic_encoding_decoding_int64.d.ts +0 -9
- package/dist2/json_basic_encoding_decoding_localizedtext.d.ts +0 -14
- package/dist2/json_basic_encoding_decoding_nodeid.d.ts +0 -33
- package/dist2/json_basic_encoding_decoding_qualifiedname.d.ts +0 -14
- package/dist2/json_basic_encoding_decoding_statuscode.d.ts +0 -16
- package/dist2/json_basic_encoding_decoding_variant.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json_basic_encoding_decoding_variant.js","sourceRoot":"","sources":["../source/json_basic_encoding_decoding_variant.ts"],"names":[],"mappings":";;AAoHA,8DAyEC;AAED,8DA+BC;AAiBD,wDAiBC;AACD,8DAgCC;AAED,8DAgCC;AACD,wDAcC;AAlVD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,2DAAyE;AAEzE,+FAA0H;AAC1H,uEAAuG;AAuEvG,QAAQ;AACR,kFAAkF;AAClF,iFAAiF;AACjF,8DAA8D;AAC9D,wFAAwF;AAExF,SAAS,IAAI,CAAC,OAAgB,EAAE,MAA0B,EAAE,cAAyB;IACjF,MAAM,CAAC,GAAG,IAAA,uDAAiB,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,OAAO,CAAC,SAAS,KAAK,qCAAgB,CAAC,MAAM,EAAE,CAAC;QAChD,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAoB,CAAC;IACvE,CAAC;SAAM,CAAC;QACJ,MAAM,KAAK,GAA4B,EAAE,CAAC;QAC1C,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAA0B,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,KAAK,CAAC;IAC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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI;KAC3D,CAAC,CAAC;AACP,CAAC;AACD,SAAgB,sBAAsB,CAClC,IAAwD,EACxD,OAA+B,EAC/B,cAAwB;IAExB,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,IAAI,4BAAO,CAAC,EAAE,QAAQ,EAAE,6BAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,CAAC;QACxC,OAAO,yBAAyB,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACpE,CAAC;SAAM,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO,yBAAyB,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { JsonDataSetMessageContentMask } from "node-opcua-types";
|
|
2
|
+
export declare enum JsonEncodingScheme {
|
|
3
|
+
Verbose = 2,
|
|
4
|
+
Compact = 3,
|
|
5
|
+
DeprecatedNonReversible = 0,// false
|
|
6
|
+
DeprecatedReversible = 1
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* JSON encoders as per 1.04
|
|
10
|
+
*/
|
|
11
|
+
export declare enum JsonEncoderMode104 {
|
|
12
|
+
Reversible = 1,
|
|
13
|
+
NonReversible = 0
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* From Part 6: 1.05.4:
|
|
17
|
+
*
|
|
18
|
+
* - The CompactEncoding omits all fields with a value equal to the default value for the type.
|
|
19
|
+
* - The VerboseEncoding includes all fields.
|
|
20
|
+
* - The CompactEncoding and VerboseEncoding replace the ReversibleEncoding and
|
|
21
|
+
* NonReversibleEncoding.
|
|
22
|
+
* The differences are described in Annex H.
|
|
23
|
+
* The VerboseEncoding also supports the RawData mode defined in OPC 10000-14.
|
|
24
|
+
*
|
|
25
|
+
* In RawData mode, encoders shall omit
|
|
26
|
+
* the following fields:
|
|
27
|
+
* UaType (see 5.4.2.17 and 5.4.2.18);
|
|
28
|
+
* UaTypeId (see 5.4.2.16);
|
|
29
|
+
* Decoders may not be able to process streams encoding in RawData mode unless they have
|
|
30
|
+
* access to the associated metadata.
|
|
31
|
+
*
|
|
32
|
+
* These fields are not omitted when serialization uses abstract DataTypes such as Structure
|
|
33
|
+
* (i.e. ExtensionObject) or BaseDataType (i.e. Variant).
|
|
34
|
+
*
|
|
35
|
+
* OPC 10000-14 specifies the behaviour if a Publisher is misconfigured with metadata that
|
|
36
|
+
* uses abstract DataTypes.
|
|
37
|
+
*/
|
|
38
|
+
export declare enum JsonEncoderMode105 {
|
|
39
|
+
Verbose = 2,
|
|
40
|
+
/**
|
|
41
|
+
* A DataEncoding where encoding the serialized form omits optional and default values.
|
|
42
|
+
*
|
|
43
|
+
* All DataEncodings are CompactEncodings unless otherwise stated.
|
|
44
|
+
*/
|
|
45
|
+
Compact = 3
|
|
46
|
+
}
|
|
47
|
+
export declare function toJsonEncodingScheme(mode: JsonEncoderMode104 | JsonEncoderMode105): JsonEncodingScheme;
|
|
48
|
+
export declare function makeDataValueEncodingEnum(fieldEncoding1: boolean, fieldEncoding2: boolean): JsonEncodingScheme;
|
|
49
|
+
export declare function JsonDataSetMessageContentMaskToJsonEncodingScheme(jsonDataMessageContentMask: JsonDataSetMessageContentMask): JsonEncodingScheme;
|
|
50
|
+
export declare function JsonEncodingSchemeToJsonDataSetMessageContentMask(scheme: JsonEncodingScheme): JsonDataSetMessageContentMask;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonEncoderMode105 = exports.JsonEncoderMode104 = exports.JsonEncodingScheme = void 0;
|
|
4
|
+
exports.toJsonEncodingScheme = toJsonEncodingScheme;
|
|
5
|
+
exports.makeDataValueEncodingEnum = makeDataValueEncodingEnum;
|
|
6
|
+
exports.JsonDataSetMessageContentMaskToJsonEncodingScheme = JsonDataSetMessageContentMaskToJsonEncodingScheme;
|
|
7
|
+
exports.JsonEncodingSchemeToJsonDataSetMessageContentMask = JsonEncodingSchemeToJsonDataSetMessageContentMask;
|
|
8
|
+
const node_opcua_types_1 = require("node-opcua-types");
|
|
9
|
+
var JsonEncodingScheme;
|
|
10
|
+
(function (JsonEncodingScheme) {
|
|
11
|
+
JsonEncodingScheme[JsonEncodingScheme["Verbose"] = 2] = "Verbose";
|
|
12
|
+
JsonEncodingScheme[JsonEncodingScheme["Compact"] = 3] = "Compact";
|
|
13
|
+
JsonEncodingScheme[JsonEncodingScheme["DeprecatedNonReversible"] = 0] = "DeprecatedNonReversible";
|
|
14
|
+
JsonEncodingScheme[JsonEncodingScheme["DeprecatedReversible"] = 1] = "DeprecatedReversible";
|
|
15
|
+
})(JsonEncodingScheme || (exports.JsonEncodingScheme = JsonEncodingScheme = {}));
|
|
16
|
+
/**
|
|
17
|
+
* JSON encoders as per 1.04
|
|
18
|
+
*/
|
|
19
|
+
var JsonEncoderMode104;
|
|
20
|
+
(function (JsonEncoderMode104) {
|
|
21
|
+
// biome-ignore lint/style/useLiteralEnumMembers: intentionally aliased to JsonEncodingScheme to keep the two enums in sync
|
|
22
|
+
JsonEncoderMode104[JsonEncoderMode104["Reversible"] = 1] = "Reversible";
|
|
23
|
+
// biome-ignore lint/style/useLiteralEnumMembers: intentionally aliased to JsonEncodingScheme to keep the two enums in sync
|
|
24
|
+
JsonEncoderMode104[JsonEncoderMode104["NonReversible"] = 0] = "NonReversible";
|
|
25
|
+
})(JsonEncoderMode104 || (exports.JsonEncoderMode104 = JsonEncoderMode104 = {}));
|
|
26
|
+
/**
|
|
27
|
+
* From Part 6: 1.05.4:
|
|
28
|
+
*
|
|
29
|
+
* - The CompactEncoding omits all fields with a value equal to the default value for the type.
|
|
30
|
+
* - The VerboseEncoding includes all fields.
|
|
31
|
+
* - The CompactEncoding and VerboseEncoding replace the ReversibleEncoding and
|
|
32
|
+
* NonReversibleEncoding.
|
|
33
|
+
* The differences are described in Annex H.
|
|
34
|
+
* The VerboseEncoding also supports the RawData mode defined in OPC 10000-14.
|
|
35
|
+
*
|
|
36
|
+
* In RawData mode, encoders shall omit
|
|
37
|
+
* the following fields:
|
|
38
|
+
* UaType (see 5.4.2.17 and 5.4.2.18);
|
|
39
|
+
* UaTypeId (see 5.4.2.16);
|
|
40
|
+
* Decoders may not be able to process streams encoding in RawData mode unless they have
|
|
41
|
+
* access to the associated metadata.
|
|
42
|
+
*
|
|
43
|
+
* These fields are not omitted when serialization uses abstract DataTypes such as Structure
|
|
44
|
+
* (i.e. ExtensionObject) or BaseDataType (i.e. Variant).
|
|
45
|
+
*
|
|
46
|
+
* OPC 10000-14 specifies the behaviour if a Publisher is misconfigured with metadata that
|
|
47
|
+
* uses abstract DataTypes.
|
|
48
|
+
*/
|
|
49
|
+
var JsonEncoderMode105;
|
|
50
|
+
(function (JsonEncoderMode105) {
|
|
51
|
+
// biome-ignore lint/style/useLiteralEnumMembers: intentionally aliased to JsonEncodingScheme to keep the two enums in sync
|
|
52
|
+
JsonEncoderMode105[JsonEncoderMode105["Verbose"] = 2] = "Verbose";
|
|
53
|
+
/**
|
|
54
|
+
* A DataEncoding where encoding the serialized form omits optional and default values.
|
|
55
|
+
*
|
|
56
|
+
* All DataEncodings are CompactEncodings unless otherwise stated.
|
|
57
|
+
*/
|
|
58
|
+
// biome-ignore lint/style/useLiteralEnumMembers: intentionally aliased to JsonEncodingScheme to keep the two enums in sync
|
|
59
|
+
JsonEncoderMode105[JsonEncoderMode105["Compact"] = 3] = "Compact";
|
|
60
|
+
})(JsonEncoderMode105 || (exports.JsonEncoderMode105 = JsonEncoderMode105 = {}));
|
|
61
|
+
function toJsonEncodingScheme(mode) {
|
|
62
|
+
switch (mode) {
|
|
63
|
+
case JsonEncoderMode104.Reversible:
|
|
64
|
+
return JsonEncodingScheme.DeprecatedReversible;
|
|
65
|
+
case JsonEncoderMode104.NonReversible:
|
|
66
|
+
return JsonEncodingScheme.DeprecatedNonReversible;
|
|
67
|
+
case JsonEncoderMode105.Verbose:
|
|
68
|
+
return JsonEncodingScheme.Verbose;
|
|
69
|
+
case JsonEncoderMode105.Compact:
|
|
70
|
+
return JsonEncodingScheme.Compact;
|
|
71
|
+
default:
|
|
72
|
+
throw new Error("Invalid JsonEncoderMode");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function makeDataValueEncodingEnum(fieldEncoding1, fieldEncoding2) {
|
|
76
|
+
// https://reference.opcfoundation.org/Core/Part14/v105/docs/6.3.2.3.1#Table112
|
|
77
|
+
/**
|
|
78
|
+
* FieldEncoding1 FieldEncoding2 Description
|
|
79
|
+
* False True The JSON VerboseEncoding is used for the
|
|
80
|
+
* DataSetMessage field encoding.
|
|
81
|
+
* True True The JSON CompactEncoding is used for the
|
|
82
|
+
* DataSetMessage field encoding.
|
|
83
|
+
* False False The deprecated JSON NonReversibleEncoding is used
|
|
84
|
+
* for the DataSetMessage field encoding.
|
|
85
|
+
* The RawData bit of the DataSetFieldContentMask shall be ignored.
|
|
86
|
+
* True False The deprecated JSON ReversibleFieldEncoding is used
|
|
87
|
+
* for the DataSetMessage field encoding.
|
|
88
|
+
* The RawData bit of the DataSetFieldContentMask shall be ignored.
|
|
89
|
+
*/
|
|
90
|
+
if (fieldEncoding2) {
|
|
91
|
+
// CompactEncoding/VerboseEncoding
|
|
92
|
+
return fieldEncoding1 ? JsonEncodingScheme.Compact : JsonEncodingScheme.Verbose;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return fieldEncoding1 ? JsonEncodingScheme.DeprecatedReversible : JsonEncodingScheme.DeprecatedNonReversible;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function JsonDataSetMessageContentMaskToJsonEncodingScheme(jsonDataMessageContentMask) {
|
|
99
|
+
const fieldEncoding1 = (jsonDataMessageContentMask & node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding1) !== 0;
|
|
100
|
+
const fieldEncoding2 = (jsonDataMessageContentMask & node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding2) !== 0;
|
|
101
|
+
return makeDataValueEncodingEnum(fieldEncoding1, fieldEncoding2);
|
|
102
|
+
}
|
|
103
|
+
function JsonEncodingSchemeToJsonDataSetMessageContentMask(scheme) {
|
|
104
|
+
switch (scheme) {
|
|
105
|
+
case JsonEncodingScheme.Verbose:
|
|
106
|
+
return node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding2;
|
|
107
|
+
case JsonEncodingScheme.Compact:
|
|
108
|
+
return node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding1 | node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding2;
|
|
109
|
+
case JsonEncodingScheme.DeprecatedReversible:
|
|
110
|
+
return node_opcua_types_1.JsonDataSetMessageContentMask.FieldEncoding1;
|
|
111
|
+
case JsonEncodingScheme.DeprecatedNonReversible:
|
|
112
|
+
return 0; // no field encoding
|
|
113
|
+
default:
|
|
114
|
+
throw new Error("Invalid JsonEncodingScheme");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=json_encoding_scheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json_encoding_scheme.js","sourceRoot":"","sources":["../source/json_encoding_scheme.ts"],"names":[],"mappings":";;;AAsDA,oDAaC;AAED,8DAsBC;AAED,8GAMC;AACD,8GAaC;AAjHD,uDAAiE;AAEjE,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC1B,iEAAW,CAAA;IACX,iEAAW,CAAA;IACX,iGAA2B,CAAA;IAC3B,2FAAwB,CAAA;AAC5B,CAAC,EALW,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36
|
-
}
|
|
2
|
+
"name": "node-opcua-json",
|
|
3
|
+
"version": "2.182.0",
|
|
4
|
+
"description": "pure nodejs OPCUA SDK - the OPC UA JSON encoding of OPC 10000-6 clause 5.4",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc -b",
|
|
7
|
+
"lint": "biome check --no-errors-on-unmatched .",
|
|
8
|
+
"clean": "npx rimraf -g node_modules dist *.tsbuildinfo",
|
|
9
|
+
"test": "mocha",
|
|
10
|
+
"test:check": "tsc --noEmit -p test/tsconfig.json"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"devEngines": {
|
|
15
|
+
"node": ">=18.x",
|
|
16
|
+
"npm": ">=10.x"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"node-opcua-basic-types": "2.182.0",
|
|
20
|
+
"node-opcua-data-model": "2.182.0",
|
|
21
|
+
"node-opcua-data-value": "2.182.0",
|
|
22
|
+
"node-opcua-date-time": "2.181.0",
|
|
23
|
+
"node-opcua-debug": "2.181.0",
|
|
24
|
+
"node-opcua-extension-object": "2.182.0",
|
|
25
|
+
"node-opcua-factory": "2.182.0",
|
|
26
|
+
"node-opcua-nodeid": "2.182.0",
|
|
27
|
+
"node-opcua-numeric-range": "2.182.0",
|
|
28
|
+
"node-opcua-status-code": "2.181.0",
|
|
29
|
+
"node-opcua-types": "2.182.0",
|
|
30
|
+
"node-opcua-variant": "2.182.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"node-opcua-address-space": "2.182.0",
|
|
34
|
+
"node-opcua-constants": "2.181.0",
|
|
35
|
+
"node-opcua-nodesets": "2.182.0"
|
|
36
|
+
},
|
|
37
|
+
"author": "Etienne Rossignon",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git://github.com/node-opcua/node-opcua.git"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"OPCUA",
|
|
45
|
+
"opcua",
|
|
46
|
+
"m2m",
|
|
47
|
+
"iot",
|
|
48
|
+
"opc ua",
|
|
49
|
+
"internet of things",
|
|
50
|
+
"json"
|
|
51
|
+
],
|
|
52
|
+
"homepage": "http://node-opcua.github.io/",
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"source"
|
|
56
|
+
],
|
|
57
|
+
"gitHead": "7172ac8333d34505a72221e8f56e8708c2c96bd7"
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==========================================================================
|
|
3
|
+
* Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
|
13
|
+
* all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
* IN THE SOFTWARE.
|
|
22
|
+
* ==========================================================================
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { ExtensionObject } from "node-opcua-extension-object";
|
|
26
|
+
import { type ConstructorFuncWithSchema, getStandardDataTypeFactory } from "node-opcua-factory";
|
|
27
|
+
import { type NodeId, type NodeIdLike, resolveNodeId } from "node-opcua-nodeid";
|
|
28
|
+
import type { ExtensionObjectConstructorFuncWithSchema } from "./extension_object_constructor.js";
|
|
29
|
+
|
|
30
|
+
import { opcuaJsonDecodeExtensionObjectBody } from "./json_basic_encoding_decoding_extension_object.js";
|
|
31
|
+
|
|
32
|
+
export type Pojo = { [key: string]: unknown };
|
|
33
|
+
|
|
34
|
+
const faekeBuilder = {
|
|
35
|
+
getExtensionObjectConstructor(_dataTypeNodeId: NodeId): ExtensionObjectConstructorFuncWithSchema {
|
|
36
|
+
return null as unknown as ExtensionObjectConstructorFuncWithSchema;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export function decodeOPCUA_JSONOld<T extends ExtensionObject>(dataType: NodeIdLike, pojo: Pojo): T | null {
|
|
40
|
+
const factory = getStandardDataTypeFactory();
|
|
41
|
+
|
|
42
|
+
const schema = factory.getStructureInfoForDataType(resolveNodeId(dataType));
|
|
43
|
+
if (!schema) return null;
|
|
44
|
+
|
|
45
|
+
const Constructor = schema.constructor;
|
|
46
|
+
if (!Constructor) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const adaptedBody = opcuaJsonDecodeExtensionObjectBody(Constructor.schema, pojo, faekeBuilder, []);
|
|
51
|
+
if (Array.isArray(adaptedBody)) {
|
|
52
|
+
throw new Error("decodeOPCUA_JSONOld: adaptedBody is an array, expected an object");
|
|
53
|
+
}
|
|
54
|
+
const extObj = new Constructor(adaptedBody);
|
|
55
|
+
return extObj as T;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function decodeOPCUA_JSON<T extends ConstructorFuncWithSchema>(Constructor: T, pojo: Pojo): InstanceType<T> {
|
|
59
|
+
const adaptedBody = opcuaJsonDecodeExtensionObjectBody(Constructor.schema, pojo, faekeBuilder, []);
|
|
60
|
+
|
|
61
|
+
if (Array.isArray(adaptedBody)) {
|
|
62
|
+
// If the adapted body is an empty array, we return null
|
|
63
|
+
throw new Error("decodeOPCUA_JSONOld: adaptedBody is an array, expected an object");
|
|
64
|
+
}
|
|
65
|
+
const extObj = new Constructor(adaptedBody);
|
|
66
|
+
return extObj as InstanceType<T>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==========================================================================
|
|
3
|
+
* Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
|
13
|
+
* all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
* IN THE SOFTWARE.
|
|
22
|
+
* ==========================================================================
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { ExtensionObject } from "node-opcua-extension-object";
|
|
26
|
+
import type { IStructuredTypeSchema } from "node-opcua-factory";
|
|
27
|
+
import type { ExpandedNodeId } from "node-opcua-nodeid";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* the constructor of a concrete ExtensionObject, together with the schema that describes it.
|
|
31
|
+
*
|
|
32
|
+
* This is `ConstructorFuncWithSchema` from node-opcua-factory narrowed to construct an
|
|
33
|
+
* ExtensionObject rather than an IBaseUAObject, which is what a JSON decoder needs: it hands back
|
|
34
|
+
* what it built, and the caller is entitled to an ExtensionObject.
|
|
35
|
+
*
|
|
36
|
+
* It is declared here rather than imported because the narrowing needs `ExtensionObject`, and
|
|
37
|
+
* node-opcua-factory cannot name that type without depending on node-opcua-extension-object, which
|
|
38
|
+
* depends on it. node-opcua-address-space declares an identical interface for the same reason; it
|
|
39
|
+
* could import this one instead, now that this package sits below it.
|
|
40
|
+
*/
|
|
41
|
+
export interface ExtensionObjectConstructorFuncWithSchema {
|
|
42
|
+
new (options?: Record<string, unknown>): ExtensionObject;
|
|
43
|
+
schema: IStructuredTypeSchema;
|
|
44
|
+
possibleFields: string[];
|
|
45
|
+
encodingDefaultBinary: ExpandedNodeId;
|
|
46
|
+
encodingDefaultXml: ExpandedNodeId;
|
|
47
|
+
encodingDefaultJson?: ExpandedNodeId;
|
|
48
|
+
}
|
package/source/index.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==========================================================================
|
|
3
|
+
* Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
|
13
|
+
* all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
* IN THE SOFTWARE.
|
|
22
|
+
* ==========================================================================
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export * from "./decode_opcua_json.js";
|
|
26
|
+
export type { ExtensionObjectConstructorFuncWithSchema } from "./extension_object_constructor.js";
|
|
27
|
+
export * from "./json_basic_encoding_body_functor.js";
|
|
28
|
+
export * from "./json_basic_encoding_decoding_byte_string.js";
|
|
29
|
+
export {
|
|
30
|
+
type DataValueJSON,
|
|
31
|
+
type DataValueJSON104,
|
|
32
|
+
type DataValueJSON105,
|
|
33
|
+
opcuaJsonDecodeDataValue,
|
|
34
|
+
opcuaJsonEncodeDataValue,
|
|
35
|
+
opcuaJsonEncodeDataValueMQTT
|
|
36
|
+
} from "./json_basic_encoding_decoding_data_value.js";
|
|
37
|
+
export * from "./json_basic_encoding_decoding_extension_object.js";
|
|
38
|
+
export {
|
|
39
|
+
opcuaJsonDecodeExtensionObject,
|
|
40
|
+
opcuaJsonEncodeExtensionObject
|
|
41
|
+
} from "./json_basic_encoding_decoding_extension_object.js";
|
|
42
|
+
export * from "./json_basic_encoding_decoding_int64.js";
|
|
43
|
+
export * from "./json_basic_encoding_decoding_localizedtext.js";
|
|
44
|
+
export * from "./json_basic_encoding_decoding_nodeid.js";
|
|
45
|
+
export * from "./json_basic_encoding_decoding_qualifiedname.js";
|
|
46
|
+
export * from "./json_basic_encoding_decoding_statuscode.js";
|
|
47
|
+
export * from "./json_basic_encoding_decoding_statuscode.js";
|
|
48
|
+
export {
|
|
49
|
+
opcuaJsonDecodeVariant,
|
|
50
|
+
// the explicit 1.05 entry points: the dispatcher above overloads Compact and Verbose together
|
|
51
|
+
// and so cannot return the 1.05 object shape for Verbose alone
|
|
52
|
+
opcuaJsonDecodeVariant105,
|
|
53
|
+
opcuaJsonEncodeVariant,
|
|
54
|
+
opcuaJsonEncodeVariant105,
|
|
55
|
+
type VariantJSON,
|
|
56
|
+
type VariantJSON104,
|
|
57
|
+
type VariantJSON105
|
|
58
|
+
} from "./json_basic_encoding_decoding_variant.js";
|
|
59
|
+
export * from "./json_encoding_scheme.js";
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ==========================================================================
|
|
3
|
+
* Copyright (c) 2021-2026 Sterfive - etienne.rossignon@sterfive.com
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
|
13
|
+
* all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
* IN THE SOFTWARE.
|
|
22
|
+
* ==========================================================================
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { NodeId } from "node-opcua-nodeid";
|
|
26
|
+
import { DataType } from "node-opcua-variant";
|
|
27
|
+
import type { ExtensionObjectConstructorFuncWithSchema } from "./extension_object_constructor.js";
|
|
28
|
+
|
|
29
|
+
import { opcuaJsonDecodeByteString, opcuaJsonEncodeByteString } from "./json_basic_encoding_decoding_byte_string.js";
|
|
30
|
+
import { opcuaJsonDecodeDataValue, opcuaJsonEncodeDataValue } from "./json_basic_encoding_decoding_data_value.js";
|
|
31
|
+
import { opcuaJsonDecodeDateTime, opcuaJsonEncodeDateTime } from "./json_basic_encoding_decoding_date_time.js";
|
|
32
|
+
import { opcuaJsonDecodeExtensionObject, opcuaJsonEncodeExtensionObject } from "./json_basic_encoding_decoding_extension_object.js";
|
|
33
|
+
import {
|
|
34
|
+
opcuaJsonDecodeInt64,
|
|
35
|
+
opcuaJsonDecodeUInt64,
|
|
36
|
+
opcuaJsonEncodeInt64,
|
|
37
|
+
opcuaJsonEncodeUInt64
|
|
38
|
+
} from "./json_basic_encoding_decoding_int64.js";
|
|
39
|
+
import { opcuaJsonDecodeLocalizedText, opcuaJsonEncodeLocalizedText } from "./json_basic_encoding_decoding_localizedtext.js";
|
|
40
|
+
import {
|
|
41
|
+
opcuaJsonDecodeExpandedNodeId,
|
|
42
|
+
opcuaJsonDecodeNodeId,
|
|
43
|
+
opcuaJsonEncodeExpandedNodeId,
|
|
44
|
+
opcuaJsonEncodeNodeId
|
|
45
|
+
} from "./json_basic_encoding_decoding_nodeid.js";
|
|
46
|
+
import { opcuaJsonDecodeQualifiedName, opcuaJsonEncodeQualifiedName } from "./json_basic_encoding_decoding_qualifiedname.js";
|
|
47
|
+
import { opcuaJsonDecodeStatusCode, opcuaJsonEncodeStatusCode } from "./json_basic_encoding_decoding_statuscode.js";
|
|
48
|
+
import { opcuaJsonDecodeVariant, opcuaJsonEncodeVariant } from "./json_basic_encoding_decoding_variant.js";
|
|
49
|
+
import { JsonEncodingScheme } from "./json_encoding_scheme.js";
|
|
50
|
+
|
|
51
|
+
export type EncoderFunc<T> = (t: T, encodingScheme: JsonEncodingScheme, namespaceArray?: string[]) => unknown;
|
|
52
|
+
|
|
53
|
+
export interface ExtensionObjectBuilder {
|
|
54
|
+
getExtensionObjectConstructor(dataTypeNodeId: NodeId): ExtensionObjectConstructorFuncWithSchema;
|
|
55
|
+
}
|
|
56
|
+
export type DecoderFunc<T> = (t: T, builder: ExtensionObjectBuilder, namespaceArray: string[]) => unknown;
|
|
57
|
+
|
|
58
|
+
function opcuaJsonEncodeString(a: string, scheme: JsonEncodingScheme): string | undefined {
|
|
59
|
+
switch (scheme) {
|
|
60
|
+
case JsonEncodingScheme.DeprecatedReversible:
|
|
61
|
+
return a;
|
|
62
|
+
case JsonEncodingScheme.DeprecatedNonReversible:
|
|
63
|
+
return a;
|
|
64
|
+
case JsonEncodingScheme.Verbose:
|
|
65
|
+
return a;
|
|
66
|
+
case JsonEncodingScheme.Compact:
|
|
67
|
+
if (a === "" || a === undefined || a === null) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return a;
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Unknown JsonEncodingScheme: ${scheme}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function opcuaJsonEncodeGuid(a: string, scheme: JsonEncodingScheme): string | undefined {
|
|
77
|
+
switch (scheme) {
|
|
78
|
+
case JsonEncodingScheme.DeprecatedReversible:
|
|
79
|
+
return a.toLowerCase();
|
|
80
|
+
case JsonEncodingScheme.DeprecatedNonReversible:
|
|
81
|
+
return a.toLowerCase();
|
|
82
|
+
case JsonEncodingScheme.Verbose:
|
|
83
|
+
return a.toLowerCase();
|
|
84
|
+
case JsonEncodingScheme.Compact:
|
|
85
|
+
if (a === "00000000-0000-0000-0000-000000000000") {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return a.toLowerCase();
|
|
89
|
+
default:
|
|
90
|
+
throw new Error(`Unknown JsonEncodingScheme: ${scheme}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function bodyEncodeFunctor(dataType: DataType): EncoderFunc<unknown> {
|
|
95
|
+
switch (dataType) {
|
|
96
|
+
case DataType.Null:
|
|
97
|
+
return () => null;
|
|
98
|
+
case DataType.Boolean:
|
|
99
|
+
case DataType.Byte:
|
|
100
|
+
case DataType.Double:
|
|
101
|
+
case DataType.Float:
|
|
102
|
+
case DataType.Int16:
|
|
103
|
+
case DataType.Int32:
|
|
104
|
+
case DataType.SByte:
|
|
105
|
+
case DataType.UInt16:
|
|
106
|
+
case DataType.UInt32:
|
|
107
|
+
return (a: unknown) => a;
|
|
108
|
+
case DataType.Guid:
|
|
109
|
+
return opcuaJsonEncodeGuid as EncoderFunc<unknown>;
|
|
110
|
+
case DataType.String:
|
|
111
|
+
return opcuaJsonEncodeString as EncoderFunc<unknown>;
|
|
112
|
+
case DataType.ByteString:
|
|
113
|
+
return opcuaJsonEncodeByteString as EncoderFunc<unknown>;
|
|
114
|
+
case DataType.LocalizedText:
|
|
115
|
+
return opcuaJsonEncodeLocalizedText as EncoderFunc<unknown>;
|
|
116
|
+
case DataType.NodeId:
|
|
117
|
+
return opcuaJsonEncodeNodeId as EncoderFunc<unknown>;
|
|
118
|
+
case DataType.ExpandedNodeId:
|
|
119
|
+
return opcuaJsonEncodeExpandedNodeId as EncoderFunc<unknown>;
|
|
120
|
+
case DataType.QualifiedName:
|
|
121
|
+
return opcuaJsonEncodeQualifiedName as EncoderFunc<unknown>;
|
|
122
|
+
case DataType.StatusCode:
|
|
123
|
+
return opcuaJsonEncodeStatusCode as EncoderFunc<unknown>;
|
|
124
|
+
case DataType.DateTime:
|
|
125
|
+
return opcuaJsonEncodeDateTime as EncoderFunc<unknown>;
|
|
126
|
+
case DataType.ExtensionObject:
|
|
127
|
+
return opcuaJsonEncodeExtensionObject as EncoderFunc<unknown>;
|
|
128
|
+
case DataType.Variant:
|
|
129
|
+
return opcuaJsonEncodeVariant as EncoderFunc<unknown>;
|
|
130
|
+
case DataType.Int64:
|
|
131
|
+
return opcuaJsonEncodeInt64 as EncoderFunc<unknown>;
|
|
132
|
+
case DataType.UInt64:
|
|
133
|
+
return opcuaJsonEncodeUInt64 as EncoderFunc<unknown>;
|
|
134
|
+
case DataType.DataValue:
|
|
135
|
+
return opcuaJsonEncodeDataValue as EncoderFunc<unknown>;
|
|
136
|
+
case DataType.DiagnosticInfo:
|
|
137
|
+
case DataType.XmlElement:
|
|
138
|
+
throw new Error(`Unsupported yet ${DataType[dataType]}`);
|
|
139
|
+
default:
|
|
140
|
+
return () => null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function bodyDecodeFunctor(dataType: DataType): DecoderFunc<unknown> {
|
|
145
|
+
switch (dataType) {
|
|
146
|
+
case DataType.Null:
|
|
147
|
+
return () => null;
|
|
148
|
+
case DataType.Boolean:
|
|
149
|
+
case DataType.Byte:
|
|
150
|
+
case DataType.Double:
|
|
151
|
+
case DataType.Float:
|
|
152
|
+
case DataType.Guid:
|
|
153
|
+
case DataType.Int16:
|
|
154
|
+
case DataType.Int32:
|
|
155
|
+
case DataType.SByte:
|
|
156
|
+
case DataType.String:
|
|
157
|
+
case DataType.UInt16:
|
|
158
|
+
case DataType.UInt32:
|
|
159
|
+
return ((a: boolean | number | string) => a) as DecoderFunc<unknown>;
|
|
160
|
+
case DataType.ByteString:
|
|
161
|
+
return opcuaJsonDecodeByteString as DecoderFunc<unknown>;
|
|
162
|
+
case DataType.LocalizedText:
|
|
163
|
+
return opcuaJsonDecodeLocalizedText as DecoderFunc<unknown>;
|
|
164
|
+
case DataType.NodeId:
|
|
165
|
+
return opcuaJsonDecodeNodeId as DecoderFunc<unknown>;
|
|
166
|
+
case DataType.ExpandedNodeId:
|
|
167
|
+
return opcuaJsonDecodeExpandedNodeId as DecoderFunc<unknown>;
|
|
168
|
+
case DataType.QualifiedName:
|
|
169
|
+
return opcuaJsonDecodeQualifiedName as DecoderFunc<unknown>;
|
|
170
|
+
case DataType.StatusCode:
|
|
171
|
+
return opcuaJsonDecodeStatusCode as DecoderFunc<unknown>;
|
|
172
|
+
case DataType.DateTime:
|
|
173
|
+
return opcuaJsonDecodeDateTime as DecoderFunc<unknown>;
|
|
174
|
+
case DataType.ExtensionObject:
|
|
175
|
+
return opcuaJsonDecodeExtensionObject as DecoderFunc<unknown>;
|
|
176
|
+
case DataType.Variant:
|
|
177
|
+
return opcuaJsonDecodeVariant as DecoderFunc<unknown>;
|
|
178
|
+
case DataType.Int64:
|
|
179
|
+
return opcuaJsonDecodeInt64 as DecoderFunc<unknown>;
|
|
180
|
+
case DataType.UInt64:
|
|
181
|
+
return opcuaJsonDecodeUInt64 as DecoderFunc<unknown>;
|
|
182
|
+
case DataType.DataValue:
|
|
183
|
+
return opcuaJsonDecodeDataValue as DecoderFunc<unknown>;
|
|
184
|
+
case DataType.DiagnosticInfo:
|
|
185
|
+
case DataType.XmlElement:
|
|
186
|
+
throw new Error(`Unsupported yet ${DataType[dataType]}`);
|
|
187
|
+
default:
|
|
188
|
+
return () => null;
|
|
189
|
+
}
|
|
190
|
+
}
|