node-opcua-packet-assembler 2.64.1 → 2.66.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/dist/index.d.ts +1 -1
- package/dist/index.js +17 -13
- package/dist/index.js.map +1 -1
- package/dist/packet_assembler.d.ts +33 -33
- package/dist/packet_assembler.js +85 -85
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./packet_assembler";
|
|
1
|
+
export * from "./packet_assembler";
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__exportStar(
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./packet_assembler"), exports);
|
|
14
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
/***
|
|
4
|
-
* @class PacketAssembler
|
|
5
|
-
* @constructor
|
|
6
|
-
*/
|
|
7
|
-
export interface MessageHeader {
|
|
8
|
-
msgType: string;
|
|
9
|
-
isFinal: string;
|
|
10
|
-
length: number;
|
|
11
|
-
}
|
|
12
|
-
export interface PacketInfo {
|
|
13
|
-
length: number;
|
|
14
|
-
messageHeader: MessageHeader;
|
|
15
|
-
extra: string;
|
|
16
|
-
}
|
|
17
|
-
export declare type ReadMessageFuncType = (data: Buffer) => PacketInfo;
|
|
18
|
-
export interface PacketAssemblerOptions {
|
|
19
|
-
readMessageFunc: ReadMessageFuncType;
|
|
20
|
-
minimumSizeInBytes: number;
|
|
21
|
-
}
|
|
22
|
-
export declare class PacketAssembler extends EventEmitter {
|
|
23
|
-
private readonly _stack;
|
|
24
|
-
private expectedLength;
|
|
25
|
-
private currentLength;
|
|
26
|
-
private readonly readMessageFunc;
|
|
27
|
-
private readonly minimumSizeInBytes;
|
|
28
|
-
private packetInfo?;
|
|
29
|
-
constructor(options: PacketAssemblerOptions);
|
|
30
|
-
feed(data: Buffer): void;
|
|
31
|
-
private _readPacketInfo;
|
|
32
|
-
private _buildData;
|
|
33
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
/***
|
|
4
|
+
* @class PacketAssembler
|
|
5
|
+
* @constructor
|
|
6
|
+
*/
|
|
7
|
+
export interface MessageHeader {
|
|
8
|
+
msgType: string;
|
|
9
|
+
isFinal: string;
|
|
10
|
+
length: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PacketInfo {
|
|
13
|
+
length: number;
|
|
14
|
+
messageHeader: MessageHeader;
|
|
15
|
+
extra: string;
|
|
16
|
+
}
|
|
17
|
+
export declare type ReadMessageFuncType = (data: Buffer) => PacketInfo;
|
|
18
|
+
export interface PacketAssemblerOptions {
|
|
19
|
+
readMessageFunc: ReadMessageFuncType;
|
|
20
|
+
minimumSizeInBytes: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class PacketAssembler extends EventEmitter {
|
|
23
|
+
private readonly _stack;
|
|
24
|
+
private expectedLength;
|
|
25
|
+
private currentLength;
|
|
26
|
+
private readonly readMessageFunc;
|
|
27
|
+
private readonly minimumSizeInBytes;
|
|
28
|
+
private packetInfo?;
|
|
29
|
+
constructor(options: PacketAssemblerOptions);
|
|
30
|
+
feed(data: Buffer): void;
|
|
31
|
+
private _readPacketInfo;
|
|
32
|
+
private _buildData;
|
|
33
|
+
}
|
package/dist/packet_assembler.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PacketAssembler = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
6
|
-
const doDebug = false;
|
|
7
|
-
class PacketAssembler extends events_1.EventEmitter {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
super();
|
|
10
|
-
this._stack = [];
|
|
11
|
-
this.expectedLength = 0;
|
|
12
|
-
this.currentLength = 0;
|
|
13
|
-
this.readMessageFunc = options.readMessageFunc;
|
|
14
|
-
this.minimumSizeInBytes = options.minimumSizeInBytes || 8;
|
|
15
|
-
(0, node_opcua_assert_1.assert)(typeof this.readMessageFunc === "function", "packet assembler requires a readMessageFunc");
|
|
16
|
-
}
|
|
17
|
-
feed(data) {
|
|
18
|
-
let messageChunk;
|
|
19
|
-
if (this.expectedLength === 0 && this.currentLength + data.length >= this.minimumSizeInBytes) {
|
|
20
|
-
// we are at a start of a block and there is enough data provided to read the length of the block
|
|
21
|
-
// let's build the whole data block with previous blocks already read.
|
|
22
|
-
if (this._stack.length > 0) {
|
|
23
|
-
data = this._buildData(data);
|
|
24
|
-
this.currentLength = 0;
|
|
25
|
-
}
|
|
26
|
-
// we can extract the expected length here
|
|
27
|
-
this.packetInfo = this._readPacketInfo(data);
|
|
28
|
-
this.expectedLength = this.packetInfo.length;
|
|
29
|
-
(0, node_opcua_assert_1.assert)(this.currentLength === 0);
|
|
30
|
-
(0, node_opcua_assert_1.assert)(this.expectedLength > 0);
|
|
31
|
-
// we can now emit an event to signal the start of a new packet
|
|
32
|
-
this.emit("newMessage", this.packetInfo, data);
|
|
33
|
-
}
|
|
34
|
-
if (this.expectedLength === 0 || this.currentLength + data.length < this.expectedLength) {
|
|
35
|
-
this._stack.push(data);
|
|
36
|
-
this.currentLength += data.length;
|
|
37
|
-
// expecting more data to complete current message chunk
|
|
38
|
-
}
|
|
39
|
-
else if (this.currentLength + data.length === this.expectedLength) {
|
|
40
|
-
this.currentLength += data.length;
|
|
41
|
-
messageChunk = this._buildData(data);
|
|
42
|
-
// istanbul ignore next
|
|
43
|
-
if (doDebug) {
|
|
44
|
-
const packetInfo = this._readPacketInfo(messageChunk);
|
|
45
|
-
(0, node_opcua_assert_1.assert)(this.packetInfo && this.packetInfo.length === packetInfo.length);
|
|
46
|
-
(0, node_opcua_assert_1.assert)(messageChunk.length === packetInfo.length);
|
|
47
|
-
}
|
|
48
|
-
// reset
|
|
49
|
-
this.currentLength = 0;
|
|
50
|
-
this.expectedLength = 0;
|
|
51
|
-
this.emit("message", messageChunk);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
// there is more data in this chunk than expected...
|
|
55
|
-
// the chunk need to be split
|
|
56
|
-
const size1 = this.expectedLength - this.currentLength;
|
|
57
|
-
if (size1 > 0) {
|
|
58
|
-
const chunk1 = data.slice(0, size1);
|
|
59
|
-
this.feed(chunk1);
|
|
60
|
-
}
|
|
61
|
-
const chunk2 = data.slice(size1);
|
|
62
|
-
if (chunk2.length > 0) {
|
|
63
|
-
this.feed(chunk2);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
_readPacketInfo(data) {
|
|
68
|
-
return this.readMessageFunc(data);
|
|
69
|
-
}
|
|
70
|
-
_buildData(data) {
|
|
71
|
-
if (data && this._stack.length === 0) {
|
|
72
|
-
return data;
|
|
73
|
-
}
|
|
74
|
-
if (!data && this._stack.length === 1) {
|
|
75
|
-
data = this._stack[0];
|
|
76
|
-
this._stack.length = 0; // empty stack array
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
this._stack.push(data);
|
|
80
|
-
data = Buffer.concat(this._stack);
|
|
81
|
-
this._stack.length = 0;
|
|
82
|
-
return data;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.PacketAssembler = PacketAssembler;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PacketAssembler = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
6
|
+
const doDebug = false;
|
|
7
|
+
class PacketAssembler extends events_1.EventEmitter {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
10
|
+
this._stack = [];
|
|
11
|
+
this.expectedLength = 0;
|
|
12
|
+
this.currentLength = 0;
|
|
13
|
+
this.readMessageFunc = options.readMessageFunc;
|
|
14
|
+
this.minimumSizeInBytes = options.minimumSizeInBytes || 8;
|
|
15
|
+
(0, node_opcua_assert_1.assert)(typeof this.readMessageFunc === "function", "packet assembler requires a readMessageFunc");
|
|
16
|
+
}
|
|
17
|
+
feed(data) {
|
|
18
|
+
let messageChunk;
|
|
19
|
+
if (this.expectedLength === 0 && this.currentLength + data.length >= this.minimumSizeInBytes) {
|
|
20
|
+
// we are at a start of a block and there is enough data provided to read the length of the block
|
|
21
|
+
// let's build the whole data block with previous blocks already read.
|
|
22
|
+
if (this._stack.length > 0) {
|
|
23
|
+
data = this._buildData(data);
|
|
24
|
+
this.currentLength = 0;
|
|
25
|
+
}
|
|
26
|
+
// we can extract the expected length here
|
|
27
|
+
this.packetInfo = this._readPacketInfo(data);
|
|
28
|
+
this.expectedLength = this.packetInfo.length;
|
|
29
|
+
(0, node_opcua_assert_1.assert)(this.currentLength === 0);
|
|
30
|
+
(0, node_opcua_assert_1.assert)(this.expectedLength > 0);
|
|
31
|
+
// we can now emit an event to signal the start of a new packet
|
|
32
|
+
this.emit("newMessage", this.packetInfo, data);
|
|
33
|
+
}
|
|
34
|
+
if (this.expectedLength === 0 || this.currentLength + data.length < this.expectedLength) {
|
|
35
|
+
this._stack.push(data);
|
|
36
|
+
this.currentLength += data.length;
|
|
37
|
+
// expecting more data to complete current message chunk
|
|
38
|
+
}
|
|
39
|
+
else if (this.currentLength + data.length === this.expectedLength) {
|
|
40
|
+
this.currentLength += data.length;
|
|
41
|
+
messageChunk = this._buildData(data);
|
|
42
|
+
// istanbul ignore next
|
|
43
|
+
if (doDebug) {
|
|
44
|
+
const packetInfo = this._readPacketInfo(messageChunk);
|
|
45
|
+
(0, node_opcua_assert_1.assert)(this.packetInfo && this.packetInfo.length === packetInfo.length);
|
|
46
|
+
(0, node_opcua_assert_1.assert)(messageChunk.length === packetInfo.length);
|
|
47
|
+
}
|
|
48
|
+
// reset
|
|
49
|
+
this.currentLength = 0;
|
|
50
|
+
this.expectedLength = 0;
|
|
51
|
+
this.emit("message", messageChunk);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// there is more data in this chunk than expected...
|
|
55
|
+
// the chunk need to be split
|
|
56
|
+
const size1 = this.expectedLength - this.currentLength;
|
|
57
|
+
if (size1 > 0) {
|
|
58
|
+
const chunk1 = data.slice(0, size1);
|
|
59
|
+
this.feed(chunk1);
|
|
60
|
+
}
|
|
61
|
+
const chunk2 = data.slice(size1);
|
|
62
|
+
if (chunk2.length > 0) {
|
|
63
|
+
this.feed(chunk2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_readPacketInfo(data) {
|
|
68
|
+
return this.readMessageFunc(data);
|
|
69
|
+
}
|
|
70
|
+
_buildData(data) {
|
|
71
|
+
if (data && this._stack.length === 0) {
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
if (!data && this._stack.length === 1) {
|
|
75
|
+
data = this._stack[0];
|
|
76
|
+
this._stack.length = 0; // empty stack array
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
this._stack.push(data);
|
|
80
|
+
data = Buffer.concat(this._stack);
|
|
81
|
+
this._stack.length = 0;
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.PacketAssembler = PacketAssembler;
|
|
86
86
|
//# sourceMappingURL=packet_assembler.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-packet-assembler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.66.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -packet-assembler",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -b",
|
|
9
|
-
"clean": "
|
|
9
|
+
"clean": "npx rimraf dist *.tsbuildinfo",
|
|
10
10
|
"test": "mocha"
|
|
11
11
|
},
|
|
12
12
|
"author": "Etienne Rossignon",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"node-opcua-assert": "2.
|
|
15
|
+
"node-opcua-assert": "2.66.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"should": "^13.2.3"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"internet of things"
|
|
31
31
|
],
|
|
32
32
|
"homepage": "http://node-opcua.github.io/",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "97f47e2e242a1fd737495fd64cb65e8fb7a9964b"
|
|
34
34
|
}
|