node-opcua-basic-types 2.54.0 → 2.60.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/.mocharc.yml CHANGED
@@ -1,10 +1,10 @@
1
- recursive: true
2
- require:
3
- - ../../node_modules/should
4
- - ../../node_modules/ts-node/register
5
- timeout: 20000
6
- enable-source-maps: true
7
- spec:
8
- - test/**/*.ts
9
- - test/**/*.js
10
- bail: true
1
+ recursive: true
2
+ require:
3
+ - ../../node_modules/should
4
+ - ../../node_modules/ts-node/register
5
+ timeout: 20000
6
+ enable-source-maps: true
7
+ spec:
8
+ - test/**/*.ts
9
+ - test/**/*.js
10
+ bail: true
package/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014-2021 Etienne Rossignon
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2021 Etienne Rossignon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -43,7 +43,7 @@ function invert(a) {
43
43
  }
44
44
  exports.attributeNameById = invert(AttributeIds);
45
45
  function isValidAttributeId(attributeId) {
46
- return attributeId >= 1 && attributeId < AttributeIds.LAST;
46
+ return attributeId >= 1 && attributeId <= AttributeIds.LAST;
47
47
  }
48
48
  exports.isValidAttributeId = isValidAttributeId;
49
49
  //# sourceMappingURL=attributeIds.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attributeIds.js","sourceRoot":"","sources":["../source/attributeIds.ts"],"names":[],"mappings":";;;AAKA,IAAY,YA+BX;AA/BD,WAAY,YAAY;IACpB,mDAAU,CAAA;IACV,yDAAa,CAAA;IACb,2DAAc,CAAA;IACd,6DAAe,CAAA;IACf,6DAAe,CAAA;IACf,yDAAa,CAAA;IACb,iEAAiB,CAAA;IACjB,2DAAc,CAAA;IACd,yDAAa,CAAA;IACb,8DAAgB,CAAA;IAChB,sEAAoB,CAAA;IACpB,kEAAkB,CAAA;IAClB,kDAAU,CAAA;IACV,wDAAa,CAAA;IACb,0DAAc,CAAA;IACd,sEAAoB,CAAA;IACpB,8DAAgB,CAAA;IAChB,sEAAoB,CAAA;IACpB,sFAA4B,CAAA;IAC5B,8DAAgB,CAAA;IAChB,4DAAe,CAAA;IACf,oEAAmB,CAAA;IACnB,cAAc;IACd,4EAAuB,CAAA;IACvB,sEAAoB,CAAA;IACpB,8EAAwB,CAAA;IACxB,4EAAuB,CAAA;IACvB,kEAAkB,CAAA;IAClB,gDAAS,CAAA;IACT,uDAAa,CAAA;AACjB,CAAC,EA/BW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA+BvB;AAED,kFAAkF;AAClF,SAAS,MAAM,CAAC,CAAqC;IACjD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QAC1C,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACT,OAAO,CAAC,CAAC;IACb,CAAC,EAAE,EAAwC,CAAC,CAAC;AACjD,CAAC;AACY,QAAA,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAEtD,SAAgB,kBAAkB,CAAC,WAAmB;IAClD,OAAO,WAAW,IAAI,CAAC,IAAI,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC;AAC/D,CAAC;AAFD,gDAEC"}
1
+ {"version":3,"file":"attributeIds.js","sourceRoot":"","sources":["../source/attributeIds.ts"],"names":[],"mappings":";;;AAKA,IAAY,YA+BX;AA/BD,WAAY,YAAY;IACpB,mDAAU,CAAA;IACV,yDAAa,CAAA;IACb,2DAAc,CAAA;IACd,6DAAe,CAAA;IACf,6DAAe,CAAA;IACf,yDAAa,CAAA;IACb,iEAAiB,CAAA;IACjB,2DAAc,CAAA;IACd,yDAAa,CAAA;IACb,8DAAgB,CAAA;IAChB,sEAAoB,CAAA;IACpB,kEAAkB,CAAA;IAClB,kDAAU,CAAA;IACV,wDAAa,CAAA;IACb,0DAAc,CAAA;IACd,sEAAoB,CAAA;IACpB,8DAAgB,CAAA;IAChB,sEAAoB,CAAA;IACpB,sFAA4B,CAAA;IAC5B,8DAAgB,CAAA;IAChB,4DAAe,CAAA;IACf,oEAAmB,CAAA;IACnB,cAAc;IACd,4EAAuB,CAAA;IACvB,sEAAoB,CAAA;IACpB,8EAAwB,CAAA;IACxB,4EAAuB,CAAA;IACvB,kEAAkB,CAAA;IAClB,gDAAS,CAAA;IACT,uDAAa,CAAA;AACjB,CAAC,EA/BW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA+BvB;AAED,kFAAkF;AAClF,SAAS,MAAM,CAAC,CAAqC;IACjD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;QAC1C,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACT,OAAO,CAAC,CAAC;IACb,CAAC,EAAE,EAAwC,CAAC,CAAC;AACjD,CAAC;AACY,QAAA,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAEtD,SAAgB,kBAAkB,CAAC,WAAmB;IAClD,OAAO,WAAW,IAAI,CAAC,IAAI,WAAW,IAAI,YAAY,CAAC,IAAI,CAAC;AAChE,CAAC;AAFD,gDAEC"}
package/nyc.config.js CHANGED
@@ -1,16 +1,16 @@
1
- module.exports = {
2
- "extension": [
3
- ".ts",
4
- ".tsx"
5
- ],
6
- "all": true,
7
- "include": [
8
- "dist/**/*.js",
9
- "source/**/*.ts",
10
-
11
- ],
12
- "exclude": [
13
- "**/*.spec.js"
14
- ],
15
- "check-coverage": true
16
- };
1
+ module.exports = {
2
+ "extension": [
3
+ ".ts",
4
+ ".tsx"
5
+ ],
6
+ "all": true,
7
+ "include": [
8
+ "dist/**/*.js",
9
+ "source/**/*.ts",
10
+
11
+ ],
12
+ "exclude": [
13
+ "**/*.spec.js"
14
+ ],
15
+ "check-coverage": true
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-basic-types",
3
- "version": "2.54.0",
3
+ "version": "2.60.0",
4
4
  "description": "pure nodejs OPCUA SDK - module -basic-types",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -11,20 +11,20 @@
11
11
  "lint": "eslint source/*.ts"
12
12
  },
13
13
  "dependencies": {
14
- "node-opcua-assert": "2.52.0",
15
- "node-opcua-binary-stream": "2.52.0",
16
- "node-opcua-buffer-utils": "2.52.0",
17
- "node-opcua-date-time": "2.52.0",
18
- "node-opcua-enum": "2.52.0",
19
- "node-opcua-guid": "2.52.0",
20
- "node-opcua-nodeid": "2.54.0",
21
- "node-opcua-status-code": "2.52.0",
22
- "node-opcua-utils": "2.54.0"
14
+ "node-opcua-assert": "2.55.0",
15
+ "node-opcua-binary-stream": "2.55.0",
16
+ "node-opcua-buffer-utils": "2.55.0",
17
+ "node-opcua-date-time": "2.60.0",
18
+ "node-opcua-enum": "2.55.0",
19
+ "node-opcua-guid": "2.55.0",
20
+ "node-opcua-nodeid": "2.60.0",
21
+ "node-opcua-status-code": "2.56.0",
22
+ "node-opcua-utils": "2.60.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/node": "16.10.1",
26
- "node-opcua-benchmarker": "2.52.0",
27
- "node-opcua-debug": "2.52.0",
25
+ "@types/node": "16.11.9",
26
+ "node-opcua-benchmarker": "2.55.0",
27
+ "node-opcua-debug": "2.60.0",
28
28
  "should": "^13.2.3"
29
29
  },
30
30
  "author": "Etienne Rossignon",
@@ -42,5 +42,5 @@
42
42
  "internet of things"
43
43
  ],
44
44
  "homepage": "http://node-opcua.github.io/",
45
- "gitHead": "d3093f76a2c8f574444fd59e98e7d53f34b83d8b"
45
+ "gitHead": "56dc8584b9118ee2f3bfb0b2e9d456b609ccbac8"
46
46
  }
package/source/array.ts CHANGED
@@ -1,46 +1,46 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- import { assert } from "node-opcua-assert";
5
- import { BinaryStream, BinaryStreamSizeCalculator, OutputBinaryStream } from "node-opcua-binary-stream";
6
-
7
- /**
8
- * @method encodeArray
9
- * @param arr the array to encode.
10
- * @param stream the stream.
11
- * @param encodeElementFunc The function to encode a single array element.
12
- */
13
- export function encodeArray(
14
- arr: any[] | null,
15
- stream: OutputBinaryStream,
16
- encodeElementFunc: (value: any, stream: OutputBinaryStream) => void
17
- ): void {
18
- if (arr === null) {
19
- stream.writeUInt32(0xffffffff);
20
- return;
21
- }
22
- assert(Array.isArray(arr));
23
- stream.writeUInt32(arr.length);
24
- for (const value of arr) {
25
- encodeElementFunc(value, stream);
26
- }
27
- }
28
-
29
- /**
30
- * decode an array from a BinaryStream
31
- * @param stream the stream.
32
- * @param decodeElementFunc The function to decode a single array element.
33
- * This function returns the element decoded from the stream
34
- * @returns an array of elements or nul
35
- */
36
- export function decodeArray(stream: BinaryStream, decodeElementFunc: (stream: BinaryStream) => any): any[] | null {
37
- const length = stream.readUInt32();
38
- if (length === 0xffffffff) {
39
- return null;
40
- }
41
- const arr = [];
42
- for (let i = 0; i < length; i++) {
43
- arr.push(decodeElementFunc(stream));
44
- }
45
- return arr;
46
- }
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ import { assert } from "node-opcua-assert";
5
+ import { BinaryStream, BinaryStreamSizeCalculator, OutputBinaryStream } from "node-opcua-binary-stream";
6
+
7
+ /**
8
+ * @method encodeArray
9
+ * @param arr the array to encode.
10
+ * @param stream the stream.
11
+ * @param encodeElementFunc The function to encode a single array element.
12
+ */
13
+ export function encodeArray(
14
+ arr: any[] | null,
15
+ stream: OutputBinaryStream,
16
+ encodeElementFunc: (value: any, stream: OutputBinaryStream) => void
17
+ ): void {
18
+ if (arr === null) {
19
+ stream.writeUInt32(0xffffffff);
20
+ return;
21
+ }
22
+ assert(Array.isArray(arr));
23
+ stream.writeUInt32(arr.length);
24
+ for (const value of arr) {
25
+ encodeElementFunc(value, stream);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * decode an array from a BinaryStream
31
+ * @param stream the stream.
32
+ * @param decodeElementFunc The function to decode a single array element.
33
+ * This function returns the element decoded from the stream
34
+ * @returns an array of elements or nul
35
+ */
36
+ export function decodeArray(stream: BinaryStream, decodeElementFunc: (stream: BinaryStream) => any): any[] | null {
37
+ const length = stream.readUInt32();
38
+ if (length === 0xffffffff) {
39
+ return null;
40
+ }
41
+ const arr = [];
42
+ for (let i = 0; i < length; i++) {
43
+ arr.push(decodeElementFunc(stream));
44
+ }
45
+ return arr;
46
+ }
@@ -46,5 +46,5 @@ function invert(a: { [key: string]: string | number }) {
46
46
  export const attributeNameById = invert(AttributeIds);
47
47
 
48
48
  export function isValidAttributeId(attributeId: number): boolean {
49
- return attributeId >= 1 && attributeId < AttributeIds.LAST;
49
+ return attributeId >= 1 && attributeId <= AttributeIds.LAST;
50
50
  }
@@ -1,6 +1,6 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- export * from "node-opcua-date-time";
5
- import { DateWithPicoseconds } from "node-opcua-date-time";
6
- export type DateTime = Date | DateWithPicoseconds | null;
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ export * from "node-opcua-date-time";
5
+ import { DateWithPicoseconds } from "node-opcua-date-time";
6
+ export type DateTime = Date | DateWithPicoseconds | null;
package/source/guid.ts CHANGED
@@ -1,137 +1,137 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
-
5
- import assert from "node-opcua-assert";
6
- import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
7
- import { emptyGuid, isValidGuid } from "node-opcua-guid";
8
-
9
- import { getRandomInt } from "./utils";
10
-
11
- export { isValidGuid, emptyGuid } from "node-opcua-guid";
12
-
13
- function toHex(i: number, nb: number): string {
14
- return ("000000000000000" + i.toString(16)).substr(-nb);
15
- }
16
-
17
- export type Guid = string;
18
-
19
- export function randomGuid(): Guid {
20
- const b = new BinaryStream(20);
21
- for (let i = 0; i < 20; i++) {
22
- b.writeUInt8(getRandomInt(0, 255));
23
- }
24
- b.rewind();
25
- const value = decodeGuid(b) as Guid;
26
- return value;
27
- }
28
-
29
- // 1 2 3
30
- // 012345678901234567890123456789012345
31
- // | | | | | | | | | | |
32
- // 12345678-1234-1234-ABCD-0123456789AB
33
- // 00000000-0000-0000-0000-000000000000";
34
-
35
- const hexCharToNum = (h: number): number => {
36
- // tslint:disable-next-line: no-bitwise
37
- const l = h & 0x5f;
38
- const r = l <= 25 ? l - 16 : l - 55;
39
- // xx assert(r >= 0 && r < 16);
40
- return r;
41
- };
42
- assert(hexCharToNum("A".charCodeAt(0)) === 10);
43
- assert(hexCharToNum("a".charCodeAt(0)) === 10);
44
- assert(hexCharToNum("b".charCodeAt(0)) === 11);
45
- assert(hexCharToNum("B".charCodeAt(0)) === 11);
46
- assert(hexCharToNum("0".charCodeAt(0)) === 0);
47
- assert(hexCharToNum("9".charCodeAt(0)) === 9);
48
- const doDebug = false;
49
-
50
- function write_UInt32(stream: OutputBinaryStream, guid: string, starts: number[]) {
51
- const n = starts.length;
52
- for (let i = 0; i < n; i++) {
53
- const start = starts[i];
54
- const d1 = hexCharToNum(guid.charCodeAt(start));
55
- const d2 = hexCharToNum(guid.charCodeAt(start + 1));
56
- const d3 = hexCharToNum(guid.charCodeAt(start + 2));
57
- const d4 = hexCharToNum(guid.charCodeAt(start + 3));
58
- const d5 = hexCharToNum(guid.charCodeAt(start + 4));
59
- const d6 = hexCharToNum(guid.charCodeAt(start + 5));
60
- const d7 = hexCharToNum(guid.charCodeAt(start + 6));
61
- const d8 = hexCharToNum(guid.charCodeAt(start + 7));
62
- // tslint:disable-next-line: no-bitwise
63
- const value = (((((((((((((d1 << 4) | d2) << 4) | d3) << 4) | d4) << 4) | d5) << 4) | d6) << 4) | d7) << 4) | d8;
64
- stream.writeInteger(value);
65
- }
66
- }
67
-
68
- function write_UInt16(stream: OutputBinaryStream, guid: string, starts: number[]) {
69
- const n = starts.length;
70
- for (let i = 0; i < n; i++) {
71
- const start = starts[i];
72
- const d1 = hexCharToNum(guid.charCodeAt(start));
73
- const d2 = hexCharToNum(guid.charCodeAt(start + 1));
74
- const d3 = hexCharToNum(guid.charCodeAt(start + 2));
75
- const d4 = hexCharToNum(guid.charCodeAt(start + 3));
76
- // tslint:disable-next-line: no-bitwise
77
- const value = (((((d1 << 4) | d2) << 4) | d3) << 4) | d4;
78
- stream.writeUInt16(value);
79
- }
80
- }
81
-
82
- function write_UInt8(stream: OutputBinaryStream, guid: string, starts: number[]) {
83
- const n = starts.length;
84
- for (let i = 0; i < n; i++) {
85
- const start = starts[i];
86
- const d1 = hexCharToNum(guid.charCodeAt(start));
87
- const d2 = hexCharToNum(guid.charCodeAt(start + 1));
88
- // tslint:disable-next-line: no-bitwise
89
- const value = (d1 << 4) | d2;
90
- stream.writeUInt8(value);
91
- }
92
- }
93
-
94
- export function encodeGuid(guid: Guid, stream: OutputBinaryStream): void {
95
- if (!isValidGuid(guid)) {
96
- throw new Error(" Invalid GUID : '" + JSON.stringify(guid) + "'");
97
- }
98
- write_UInt32(stream, guid, [0]);
99
- write_UInt16(stream, guid, [9, 14]);
100
- write_UInt8(stream, guid, [19, 21, 24, 26, 28, 30, 32, 34]);
101
- }
102
-
103
- function read_UInt32(stream: BinaryStream) {
104
- return toHex(stream.readUInt32(), 8);
105
- }
106
-
107
- function read_UInt16(stream: BinaryStream) {
108
- return toHex(stream.readUInt16(), 4);
109
- }
110
-
111
- function read_UInt8(stream: BinaryStream) {
112
- return toHex(stream.readUInt8(), 2);
113
- }
114
-
115
- function read_many(stream: BinaryStream, func: (stream: BinaryStream) => string, nb: number): string {
116
- let result = "";
117
- for (let i = 0; i < nb; i++) {
118
- result += func(stream);
119
- }
120
- return result;
121
- }
122
-
123
- export function decodeGuid(stream: BinaryStream, value?: Guid): Guid {
124
- const data1 = read_UInt32(stream);
125
-
126
- const data2 = read_UInt16(stream);
127
-
128
- const data3 = read_UInt16(stream);
129
-
130
- const data45 = read_many(stream, read_UInt8, 2);
131
-
132
- const data6B = read_many(stream, read_UInt8, 6);
133
-
134
- const guid = data1 + "-" + data2 + "-" + data3 + "-" + data45 + "-" + data6B;
135
-
136
- return guid.toUpperCase();
137
- }
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+
5
+ import assert from "node-opcua-assert";
6
+ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";
7
+ import { emptyGuid, isValidGuid } from "node-opcua-guid";
8
+
9
+ import { getRandomInt } from "./utils";
10
+
11
+ export { isValidGuid, emptyGuid } from "node-opcua-guid";
12
+
13
+ function toHex(i: number, nb: number): string {
14
+ return ("000000000000000" + i.toString(16)).substr(-nb);
15
+ }
16
+
17
+ export type Guid = string;
18
+
19
+ export function randomGuid(): Guid {
20
+ const b = new BinaryStream(20);
21
+ for (let i = 0; i < 20; i++) {
22
+ b.writeUInt8(getRandomInt(0, 255));
23
+ }
24
+ b.rewind();
25
+ const value = decodeGuid(b) as Guid;
26
+ return value;
27
+ }
28
+
29
+ // 1 2 3
30
+ // 012345678901234567890123456789012345
31
+ // | | | | | | | | | | |
32
+ // 12345678-1234-1234-ABCD-0123456789AB
33
+ // 00000000-0000-0000-0000-000000000000";
34
+
35
+ const hexCharToNum = (h: number): number => {
36
+ // tslint:disable-next-line: no-bitwise
37
+ const l = h & 0x5f;
38
+ const r = l <= 25 ? l - 16 : l - 55;
39
+ // xx assert(r >= 0 && r < 16);
40
+ return r;
41
+ };
42
+ assert(hexCharToNum("A".charCodeAt(0)) === 10);
43
+ assert(hexCharToNum("a".charCodeAt(0)) === 10);
44
+ assert(hexCharToNum("b".charCodeAt(0)) === 11);
45
+ assert(hexCharToNum("B".charCodeAt(0)) === 11);
46
+ assert(hexCharToNum("0".charCodeAt(0)) === 0);
47
+ assert(hexCharToNum("9".charCodeAt(0)) === 9);
48
+ const doDebug = false;
49
+
50
+ function write_UInt32(stream: OutputBinaryStream, guid: string, starts: number[]) {
51
+ const n = starts.length;
52
+ for (let i = 0; i < n; i++) {
53
+ const start = starts[i];
54
+ const d1 = hexCharToNum(guid.charCodeAt(start));
55
+ const d2 = hexCharToNum(guid.charCodeAt(start + 1));
56
+ const d3 = hexCharToNum(guid.charCodeAt(start + 2));
57
+ const d4 = hexCharToNum(guid.charCodeAt(start + 3));
58
+ const d5 = hexCharToNum(guid.charCodeAt(start + 4));
59
+ const d6 = hexCharToNum(guid.charCodeAt(start + 5));
60
+ const d7 = hexCharToNum(guid.charCodeAt(start + 6));
61
+ const d8 = hexCharToNum(guid.charCodeAt(start + 7));
62
+ // tslint:disable-next-line: no-bitwise
63
+ const value = (((((((((((((d1 << 4) | d2) << 4) | d3) << 4) | d4) << 4) | d5) << 4) | d6) << 4) | d7) << 4) | d8;
64
+ stream.writeInteger(value);
65
+ }
66
+ }
67
+
68
+ function write_UInt16(stream: OutputBinaryStream, guid: string, starts: number[]) {
69
+ const n = starts.length;
70
+ for (let i = 0; i < n; i++) {
71
+ const start = starts[i];
72
+ const d1 = hexCharToNum(guid.charCodeAt(start));
73
+ const d2 = hexCharToNum(guid.charCodeAt(start + 1));
74
+ const d3 = hexCharToNum(guid.charCodeAt(start + 2));
75
+ const d4 = hexCharToNum(guid.charCodeAt(start + 3));
76
+ // tslint:disable-next-line: no-bitwise
77
+ const value = (((((d1 << 4) | d2) << 4) | d3) << 4) | d4;
78
+ stream.writeUInt16(value);
79
+ }
80
+ }
81
+
82
+ function write_UInt8(stream: OutputBinaryStream, guid: string, starts: number[]) {
83
+ const n = starts.length;
84
+ for (let i = 0; i < n; i++) {
85
+ const start = starts[i];
86
+ const d1 = hexCharToNum(guid.charCodeAt(start));
87
+ const d2 = hexCharToNum(guid.charCodeAt(start + 1));
88
+ // tslint:disable-next-line: no-bitwise
89
+ const value = (d1 << 4) | d2;
90
+ stream.writeUInt8(value);
91
+ }
92
+ }
93
+
94
+ export function encodeGuid(guid: Guid, stream: OutputBinaryStream): void {
95
+ if (!isValidGuid(guid)) {
96
+ throw new Error(" Invalid GUID : '" + JSON.stringify(guid) + "'");
97
+ }
98
+ write_UInt32(stream, guid, [0]);
99
+ write_UInt16(stream, guid, [9, 14]);
100
+ write_UInt8(stream, guid, [19, 21, 24, 26, 28, 30, 32, 34]);
101
+ }
102
+
103
+ function read_UInt32(stream: BinaryStream) {
104
+ return toHex(stream.readUInt32(), 8);
105
+ }
106
+
107
+ function read_UInt16(stream: BinaryStream) {
108
+ return toHex(stream.readUInt16(), 4);
109
+ }
110
+
111
+ function read_UInt8(stream: BinaryStream) {
112
+ return toHex(stream.readUInt8(), 2);
113
+ }
114
+
115
+ function read_many(stream: BinaryStream, func: (stream: BinaryStream) => string, nb: number): string {
116
+ let result = "";
117
+ for (let i = 0; i < nb; i++) {
118
+ result += func(stream);
119
+ }
120
+ return result;
121
+ }
122
+
123
+ export function decodeGuid(stream: BinaryStream, value?: Guid): Guid {
124
+ const data1 = read_UInt32(stream);
125
+
126
+ const data2 = read_UInt16(stream);
127
+
128
+ const data3 = read_UInt16(stream);
129
+
130
+ const data45 = read_many(stream, read_UInt8, 2);
131
+
132
+ const data6B = read_many(stream, read_UInt8, 6);
133
+
134
+ const guid = data1 + "-" + data2 + "-" + data3 + "-" + data45 + "-" + data6B;
135
+
136
+ return guid.toUpperCase();
137
+ }
package/source/index.ts CHANGED
@@ -1,18 +1,18 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
-
5
- export * from "./boolean";
6
- export * from "./integers";
7
- export * from "./floats";
8
- export * from "./string";
9
- export * from "./date_time";
10
- export * from "./byte_string";
11
- export * from "./node_id";
12
- export * from "./status_code";
13
- export * from "./guid";
14
- export * from "./array";
15
- export * from "./locale_id";
16
- export * from "./attributeIds";
17
- export * from "./round_to_float";
18
- export type ByteString = Buffer;
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+
5
+ export * from "./boolean";
6
+ export * from "./integers";
7
+ export * from "./floats";
8
+ export * from "./string";
9
+ export * from "./date_time";
10
+ export * from "./byte_string";
11
+ export * from "./node_id";
12
+ export * from "./status_code";
13
+ export * from "./guid";
14
+ export * from "./array";
15
+ export * from "./locale_id";
16
+ export * from "./attributeIds";
17
+ export * from "./round_to_float";
18
+ export type ByteString = Buffer;
@@ -1,23 +1,23 @@
1
- export function roundToFloat2(float: number): number {
2
- if (float === 0) {
3
- return float;
4
- }
5
- // this method artificially rounds a float to 7 significant digit in base 10
6
- // Note:
7
- // this is to overcome the that that Javascript doesn't provide single precision float values (32 bits)
8
- // but only double precision float values
9
-
10
- // wikipedia:(http://en.wikipedia.org/wiki/Floating_point)
11
- //
12
- // * Single precision, usually used to represent the "float" type in the C language family
13
- // (though this is not guaranteed). This is a binary format that occupies 32 bits (4 bytes) and its
14
- // significand has a precision of 24 bits (about 7 decimal digits).
15
- // * Double precision, usually used to represent the "double" type in the C language family
16
- // (though this is not guaranteed). This is a binary format that occupies 64 bits (8 bytes) and its
17
- // significand has a precision of 53 bits (about 16 decimal digits).
18
- //
19
- const nbDigits = Math.ceil(Math.log(Math.abs(float)) / Math.log(10));
20
- const scale = Math.pow(10, -nbDigits + 2);
21
- return Math.round(float * scale) / scale;
22
- // return (float > 0 && r < 0) || (float < 0 && r > 0) ? -r : r;
23
- }
1
+ export function roundToFloat2(float: number): number {
2
+ if (float === 0) {
3
+ return float;
4
+ }
5
+ // this method artificially rounds a float to 7 significant digit in base 10
6
+ // Note:
7
+ // this is to overcome the that that Javascript doesn't provide single precision float values (32 bits)
8
+ // but only double precision float values
9
+
10
+ // wikipedia:(http://en.wikipedia.org/wiki/Floating_point)
11
+ //
12
+ // * Single precision, usually used to represent the "float" type in the C language family
13
+ // (though this is not guaranteed). This is a binary format that occupies 32 bits (4 bytes) and its
14
+ // significand has a precision of 24 bits (about 7 decimal digits).
15
+ // * Double precision, usually used to represent the "double" type in the C language family
16
+ // (though this is not guaranteed). This is a binary format that occupies 64 bits (8 bytes) and its
17
+ // significand has a precision of 53 bits (about 16 decimal digits).
18
+ //
19
+ const nbDigits = Math.ceil(Math.log(Math.abs(float)) / Math.log(10));
20
+ const scale = Math.pow(10, -nbDigits + 2);
21
+ return Math.round(float * scale) / scale;
22
+ // return (float > 0 && r < 0) || (float < 0 && r > 0) ? -r : r;
23
+ }
@@ -1,4 +1,4 @@
1
- /***
2
- * @module node-opcua-basic-types
3
- */
4
- export * from "node-opcua-status-code";
1
+ /***
2
+ * @module node-opcua-basic-types
3
+ */
4
+ export * from "node-opcua-status-code";