node-opcua-packet-assembler 2.90.0 → 2.98.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-packet-assembler",
3
- "version": "2.90.0",
3
+ "version": "2.98.0",
4
4
  "description": "pure nodejs OPCUA SDK - module -packet-assembler",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -13,11 +13,11 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "node-opcua-assert": "2.88.0",
16
- "node-opcua-debug": "2.90.0"
16
+ "node-opcua-debug": "2.98.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "should": "^13.2.3",
20
- "sinon": "^15.0.1"
20
+ "sinon": "^15.0.3"
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",
@@ -32,5 +32,5 @@
32
32
  "internet of things"
33
33
  ],
34
34
  "homepage": "http://node-opcua.github.io/",
35
- "gitHead": "d55f9150c3ffa5b86fbe1a0baba69a2543c3090a"
35
+ "gitHead": "e4d73afdfcccb3491423149d9b9785888f4ebb3c"
36
36
  }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./packet_assembler";
package/dist/index.js DELETED
@@ -1,18 +0,0 @@
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);
18
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
@@ -1,51 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EventEmitter } from "events";
4
- /***
5
- * @class PacketAssembler
6
- * @constructor
7
- */
8
- export interface MessageHeader {
9
- msgType: string;
10
- isFinal: string;
11
- length: number;
12
- }
13
- export interface PacketInfo {
14
- length: number;
15
- messageHeader: MessageHeader;
16
- extra: string;
17
- }
18
- export declare type ReadChunkFuncType = (data: Buffer) => PacketInfo;
19
- export interface PacketAssemblerOptions {
20
- readChunkFunc: ReadChunkFuncType;
21
- minimumSizeInBytes: number;
22
- maxChunkSize: number;
23
- }
24
- export declare enum PacketAssemblerErrorCode {
25
- ChunkSizeExceeded = 1,
26
- ChunkTooSmall = 2
27
- }
28
- export interface PacketAssembler {
29
- on(eventName: "startChunk", eventHandler: (packetInfo: PacketInfo, partial: Buffer) => void): this;
30
- on(eventName: "chunk", eventHandler: (chunk: Buffer) => void): this;
31
- on(eventName: "error", eventHandler: (err: Error, errCode: PacketAssemblerErrorCode) => void): this;
32
- }
33
- /**
34
- * this class is used to assemble partial data from the tranport layer
35
- * into message chunks
36
- */
37
- export declare class PacketAssembler extends EventEmitter {
38
- static defaultMaxChunkCount: number;
39
- static defaultMaxMessageSize: number;
40
- private readonly _stack;
41
- private expectedLength;
42
- private currentLength;
43
- private maxChunkSize;
44
- private readonly readChunkFunc;
45
- private readonly minimumSizeInBytes;
46
- private packetInfo?;
47
- constructor(options: PacketAssemblerOptions);
48
- feed(data: Buffer): void;
49
- private _readPacketInfo;
50
- private _buildData;
51
- }
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PacketAssembler = exports.PacketAssemblerErrorCode = void 0;
4
- const events_1 = require("events");
5
- const node_opcua_assert_1 = require("node-opcua-assert");
6
- const node_opcua_debug_1 = require("node-opcua-debug");
7
- const doDebug = false;
8
- const warningLog = (0, node_opcua_debug_1.make_warningLog)("PacketAssembler");
9
- var PacketAssemblerErrorCode;
10
- (function (PacketAssemblerErrorCode) {
11
- PacketAssemblerErrorCode[PacketAssemblerErrorCode["ChunkSizeExceeded"] = 1] = "ChunkSizeExceeded";
12
- PacketAssemblerErrorCode[PacketAssemblerErrorCode["ChunkTooSmall"] = 2] = "ChunkTooSmall";
13
- })(PacketAssemblerErrorCode = exports.PacketAssemblerErrorCode || (exports.PacketAssemblerErrorCode = {}));
14
- /**
15
- * this class is used to assemble partial data from the tranport layer
16
- * into message chunks
17
- */
18
- class PacketAssembler extends events_1.EventEmitter {
19
- constructor(options) {
20
- super();
21
- this._stack = [];
22
- this.expectedLength = 0;
23
- this.currentLength = 0;
24
- this.readChunkFunc = options.readChunkFunc;
25
- this.minimumSizeInBytes = options.minimumSizeInBytes || 8;
26
- (0, node_opcua_assert_1.assert)(typeof this.readChunkFunc === "function", "packet assembler requires a readChunkFunc");
27
- // istanbul ignore next
28
- (0, node_opcua_assert_1.assert)(options.maxChunkSize === undefined || options.maxChunkSize !== 0);
29
- this.maxChunkSize = options.maxChunkSize || PacketAssembler.defaultMaxMessageSize;
30
- (0, node_opcua_assert_1.assert)(this.maxChunkSize >= this.minimumSizeInBytes);
31
- }
32
- feed(data) {
33
- let messageChunk;
34
- if (this.expectedLength === 0 && this.currentLength + data.length >= this.minimumSizeInBytes) {
35
- // we are at a start of a block and there is enough data provided to read the length of the block
36
- // let's build the whole data block with previous blocks already read.
37
- if (this._stack.length > 0) {
38
- data = this._buildData(data);
39
- this.currentLength = 0;
40
- }
41
- // we can extract the expected length here
42
- this.packetInfo = this._readPacketInfo(data);
43
- (0, node_opcua_assert_1.assert)(this.currentLength === 0);
44
- if (this.packetInfo.length < this.minimumSizeInBytes) {
45
- this.emit("error", new Error("chunk is too small "), PacketAssemblerErrorCode.ChunkTooSmall);
46
- return;
47
- }
48
- if (this.packetInfo.length > this.maxChunkSize) {
49
- const message = `maximum chunk size exceeded (maxChunkSize=${this.maxChunkSize} current chunk size = ${this.packetInfo.length})`;
50
- warningLog(message);
51
- this.emit("error", new Error(message), PacketAssemblerErrorCode.ChunkSizeExceeded);
52
- return;
53
- }
54
- // we can now emit an event to signal the start of a new packet
55
- this.emit("startChunk", this.packetInfo, data);
56
- this.expectedLength = this.packetInfo.length;
57
- }
58
- if (this.expectedLength === 0 || this.currentLength + data.length < this.expectedLength) {
59
- this._stack.push(data);
60
- this.currentLength += data.length;
61
- // expecting more data to complete current message chunk
62
- }
63
- else if (this.currentLength + data.length === this.expectedLength) {
64
- this.currentLength += data.length;
65
- messageChunk = this._buildData(data);
66
- // istanbul ignore next
67
- if (doDebug) {
68
- const packetInfo = this._readPacketInfo(messageChunk);
69
- (0, node_opcua_assert_1.assert)(this.packetInfo && this.packetInfo.length === packetInfo.length);
70
- (0, node_opcua_assert_1.assert)(messageChunk.length === packetInfo.length);
71
- }
72
- // reset
73
- this.currentLength = 0;
74
- this.expectedLength = 0;
75
- this.emit("chunk", messageChunk);
76
- }
77
- else {
78
- // there is more data in this chunk than expected...
79
- // the chunk need to be split
80
- const size1 = this.expectedLength - this.currentLength;
81
- if (size1 > 0) {
82
- const chunk1 = data.subarray(0, size1);
83
- this.feed(chunk1);
84
- }
85
- const chunk2 = data.subarray(size1);
86
- if (chunk2.length > 0) {
87
- this.feed(chunk2);
88
- }
89
- }
90
- }
91
- _readPacketInfo(data) {
92
- return this.readChunkFunc(data);
93
- }
94
- _buildData(data) {
95
- if (data && this._stack.length === 0) {
96
- return data;
97
- }
98
- if (!data && this._stack.length === 1) {
99
- data = this._stack[0];
100
- this._stack.length = 0; // empty stack array
101
- return data;
102
- }
103
- this._stack.push(data);
104
- data = Buffer.concat(this._stack);
105
- this._stack.length = 0;
106
- return data;
107
- }
108
- }
109
- exports.PacketAssembler = PacketAssembler;
110
- PacketAssembler.defaultMaxChunkCount = 777;
111
- PacketAssembler.defaultMaxMessageSize = 1024 * 64 - 7;
112
- //# sourceMappingURL=packet_assembler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packet_assembler.js","sourceRoot":"","sources":["../source/packet_assembler.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,yDAA2C;AAC3C,uDAAmD;AAEnD,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,UAAU,GAAG,IAAA,kCAAe,EAAC,iBAAiB,CAAC,CAAC;AA4BtD,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAChC,iGAAqB,CAAA;IACrB,yFAAiB,CAAA;AACrB,CAAC,EAHW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAGnC;AAMD;;;GAGG;AACH,MAAa,eAAgB,SAAQ,qBAAY;IAc7C,YAAY,OAA+B;QACvC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,CAAC,CAAC;QAC1D,IAAA,0BAAM,EAAC,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,EAAE,2CAA2C,CAAC,CAAC;QAE9F,uBAAuB;QACvB,IAAA,0BAAM,EAAC,OAAO,CAAC,YAAY,KAAK,SAAS,IAAI,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC;QAEzE,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC,qBAAqB,CAAC;QAClF,IAAA,0BAAM,EAAC,IAAI,CAAC,YAA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