node-opcua-binary-stream 2.98.0 → 2.104.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/binaryStream.d.ts +161 -0
- package/dist/binaryStream.js +437 -0
- package/dist/binaryStream.js.map +1 -0
- package/dist/binaryStreamSizeCalculator.d.ts +29 -0
- package/dist/binaryStreamSizeCalculator.js +77 -0
- package/dist/binaryStreamSizeCalculator.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/package.json +10 -6
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-binary-stream
|
|
4
|
+
*/
|
|
5
|
+
import "util";
|
|
6
|
+
/**
|
|
7
|
+
* a BinaryStream can be use to perform sequential read or write
|
|
8
|
+
* inside a buffer.
|
|
9
|
+
* The BinaryStream maintains a cursor up to date as the caller
|
|
10
|
+
* operates on the stream using the various read/write methods.
|
|
11
|
+
* It uses the [Little Endian](http://en.wikipedia.org/wiki/Little_endian#Little-endian)
|
|
12
|
+
* It uses the [Little Endian](http://en.wikipedia.org/wiki/Little_endian#Little-endian)
|
|
13
|
+
* convention.
|
|
14
|
+
*
|
|
15
|
+
* data can either be:
|
|
16
|
+
*
|
|
17
|
+
* * a Buffer , in this case the BinaryStream operates on this Buffer
|
|
18
|
+
* * null , in this case a BinaryStream with 1024 bytes is created
|
|
19
|
+
* * any data , in this case the object is converted into a binary buffer.
|
|
20
|
+
*
|
|
21
|
+
* example:
|
|
22
|
+
*
|
|
23
|
+
* ``` javascript
|
|
24
|
+
* var stream = new BinaryStream(32)
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @class BinaryStream
|
|
28
|
+
* @param {null|Buffer|Number} data
|
|
29
|
+
* @constructor
|
|
30
|
+
*
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export declare class BinaryStream {
|
|
35
|
+
static maxByteStringLength: number;
|
|
36
|
+
static maxStringLength: number;
|
|
37
|
+
/**
|
|
38
|
+
* the current position inside the buffer
|
|
39
|
+
*/
|
|
40
|
+
length: number;
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
buffer: Buffer;
|
|
45
|
+
constructor(data: undefined | Buffer | number);
|
|
46
|
+
/**
|
|
47
|
+
* set the cursor to the begining of the stream
|
|
48
|
+
* @method BinaryStream.rewind
|
|
49
|
+
*/
|
|
50
|
+
rewind(): void;
|
|
51
|
+
/**
|
|
52
|
+
* write a single signed byte (8 bits) to the stream.
|
|
53
|
+
* value must be in the range of [-127,128]
|
|
54
|
+
* @param value the value to write
|
|
55
|
+
*/
|
|
56
|
+
writeInt8(value: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* write a single unsigned byte (8 bits) to the stream.
|
|
59
|
+
* @param value the value to write
|
|
60
|
+
*/
|
|
61
|
+
writeUInt8(value: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* write a single 16 bit signed integer to the stream.
|
|
64
|
+
* @param value the value to write
|
|
65
|
+
*/
|
|
66
|
+
writeInt16(value: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* write a single 16 bit unsigned integer to the stream.
|
|
69
|
+
* @param value the value to write
|
|
70
|
+
*/
|
|
71
|
+
writeUInt16(value: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* write a single 32 bit signed integer to the stream.
|
|
74
|
+
* @param value the value to write
|
|
75
|
+
*/
|
|
76
|
+
writeInteger(value: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* write a single 32 bit unsigned integer to the stream.
|
|
79
|
+
*
|
|
80
|
+
* @param value the value to write
|
|
81
|
+
*/
|
|
82
|
+
writeUInt32(value: number): void;
|
|
83
|
+
/**
|
|
84
|
+
* write a single 32 bit floating number to the stream.
|
|
85
|
+
* @param value the value to write
|
|
86
|
+
*/
|
|
87
|
+
writeFloat(value: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* write a single 64 bit floating number to the stream.
|
|
90
|
+
* @param value the value to write
|
|
91
|
+
*/
|
|
92
|
+
writeDouble(value: number): void;
|
|
93
|
+
/**
|
|
94
|
+
* @param arrayBuf a buffer or byte array write
|
|
95
|
+
* @param offset the offset position (default =0)
|
|
96
|
+
* @param length the number of byte to write
|
|
97
|
+
*/
|
|
98
|
+
writeArrayBuffer(arrayBuf: ArrayBuffer, offset?: number, length?: number): void;
|
|
99
|
+
/**
|
|
100
|
+
* read a single signed byte (8 bits) from the stream.
|
|
101
|
+
* @return the value read
|
|
102
|
+
*/
|
|
103
|
+
readByte(): number;
|
|
104
|
+
readInt8(): number;
|
|
105
|
+
/**
|
|
106
|
+
* read a single unsigned byte (8 bits) from the stream.
|
|
107
|
+
*/
|
|
108
|
+
readUInt8(): number;
|
|
109
|
+
/**
|
|
110
|
+
* read a single signed 16-bit integer from the stream.
|
|
111
|
+
*/
|
|
112
|
+
readInt16(): number;
|
|
113
|
+
/**
|
|
114
|
+
* read a single unsigned 16-bit integer from the stream.
|
|
115
|
+
*/
|
|
116
|
+
readUInt16(): number;
|
|
117
|
+
/**
|
|
118
|
+
* read a single signed 32-bit integer from the stream.
|
|
119
|
+
*/
|
|
120
|
+
readInteger(): number;
|
|
121
|
+
/**
|
|
122
|
+
* read a single unsigned 32-bit integer from the stream.
|
|
123
|
+
*/
|
|
124
|
+
readUInt32(): number;
|
|
125
|
+
/**
|
|
126
|
+
* read a single 32-bit floating point number from the stream.
|
|
127
|
+
*/
|
|
128
|
+
readFloat(): number;
|
|
129
|
+
/**
|
|
130
|
+
* read a single 64-bit floating point number from the stream.
|
|
131
|
+
*/
|
|
132
|
+
readDouble(): number;
|
|
133
|
+
/**
|
|
134
|
+
* write a byte stream to the stream.
|
|
135
|
+
* The method writes the length of the byte array into the stream as a 32 bits integer before the byte stream.
|
|
136
|
+
*
|
|
137
|
+
* @param buf the buffer to write.
|
|
138
|
+
*/
|
|
139
|
+
writeByteStream(buf: Buffer): void;
|
|
140
|
+
writeString(value: null | string): void;
|
|
141
|
+
/**
|
|
142
|
+
* @method readArrayBuffer
|
|
143
|
+
* @param length
|
|
144
|
+
*/
|
|
145
|
+
readArrayBuffer(length: number): Uint8Array;
|
|
146
|
+
/**
|
|
147
|
+
* read a byte stream to the stream.
|
|
148
|
+
* The method reads the length of the byte array from the stream as a 32 bits integer
|
|
149
|
+
* before reading the byte stream.
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
152
|
+
readByteStream(): Buffer | null;
|
|
153
|
+
readString(): string | null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @function calculateByteLength
|
|
157
|
+
* calculate the size in bytes of a utf8 string
|
|
158
|
+
* @param str {String}
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
export declare function calculateByteLength(str: string): number;
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateByteLength = exports.BinaryStream = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-binary-stream
|
|
6
|
+
*/
|
|
7
|
+
require("util");
|
|
8
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
+
const node_opcua_buffer_utils_1 = require("node-opcua-buffer-utils");
|
|
10
|
+
const MAXUINT32 = 4294967295; // 2**32 -1;
|
|
11
|
+
const noAssert = false;
|
|
12
|
+
const performCheck = false;
|
|
13
|
+
/**
|
|
14
|
+
* a BinaryStream can be use to perform sequential read or write
|
|
15
|
+
* inside a buffer.
|
|
16
|
+
* The BinaryStream maintains a cursor up to date as the caller
|
|
17
|
+
* operates on the stream using the various read/write methods.
|
|
18
|
+
* It uses the [Little Endian](http://en.wikipedia.org/wiki/Little_endian#Little-endian)
|
|
19
|
+
* It uses the [Little Endian](http://en.wikipedia.org/wiki/Little_endian#Little-endian)
|
|
20
|
+
* convention.
|
|
21
|
+
*
|
|
22
|
+
* data can either be:
|
|
23
|
+
*
|
|
24
|
+
* * a Buffer , in this case the BinaryStream operates on this Buffer
|
|
25
|
+
* * null , in this case a BinaryStream with 1024 bytes is created
|
|
26
|
+
* * any data , in this case the object is converted into a binary buffer.
|
|
27
|
+
*
|
|
28
|
+
* example:
|
|
29
|
+
*
|
|
30
|
+
* ``` javascript
|
|
31
|
+
* var stream = new BinaryStream(32)
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @class BinaryStream
|
|
35
|
+
* @param {null|Buffer|Number} data
|
|
36
|
+
* @constructor
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
class BinaryStream {
|
|
42
|
+
constructor(data) {
|
|
43
|
+
if (data === undefined) {
|
|
44
|
+
this.buffer = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(1024);
|
|
45
|
+
}
|
|
46
|
+
else if (typeof data === "number") {
|
|
47
|
+
this.buffer = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
(0, node_opcua_assert_1.assert)(data instanceof Buffer);
|
|
51
|
+
this.buffer = data;
|
|
52
|
+
}
|
|
53
|
+
this.length = 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* set the cursor to the begining of the stream
|
|
57
|
+
* @method BinaryStream.rewind
|
|
58
|
+
*/
|
|
59
|
+
rewind() {
|
|
60
|
+
this.length = 0;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* write a single signed byte (8 bits) to the stream.
|
|
64
|
+
* value must be in the range of [-127,128]
|
|
65
|
+
* @param value the value to write
|
|
66
|
+
*/
|
|
67
|
+
writeInt8(value) {
|
|
68
|
+
// istanbul ignore next
|
|
69
|
+
if (performCheck) {
|
|
70
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 1, "not enough space in buffer");
|
|
71
|
+
(0, node_opcua_assert_1.assert)(value >= -128 && value < 128);
|
|
72
|
+
}
|
|
73
|
+
this.buffer.writeInt8(value, this.length);
|
|
74
|
+
this.length += 1;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* write a single unsigned byte (8 bits) to the stream.
|
|
78
|
+
* @param value the value to write
|
|
79
|
+
*/
|
|
80
|
+
writeUInt8(value) {
|
|
81
|
+
// istanbul ignore next
|
|
82
|
+
if (performCheck) {
|
|
83
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 1, "not enough space in buffer");
|
|
84
|
+
(0, node_opcua_assert_1.assert)(value >= 0 && value < 256, " writeUInt8 : out of bound ");
|
|
85
|
+
}
|
|
86
|
+
this.buffer.writeUInt8(value, this.length);
|
|
87
|
+
this.length += 1;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* write a single 16 bit signed integer to the stream.
|
|
91
|
+
* @param value the value to write
|
|
92
|
+
*/
|
|
93
|
+
writeInt16(value) {
|
|
94
|
+
// istanbul ignore next
|
|
95
|
+
if (performCheck) {
|
|
96
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 2, "not enough space in buffer");
|
|
97
|
+
}
|
|
98
|
+
this.buffer.writeInt16LE(value, this.length);
|
|
99
|
+
this.length += 2;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* write a single 16 bit unsigned integer to the stream.
|
|
103
|
+
* @param value the value to write
|
|
104
|
+
*/
|
|
105
|
+
writeUInt16(value) {
|
|
106
|
+
// istanbul ignore next
|
|
107
|
+
if (performCheck) {
|
|
108
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 2, "not enough space in buffer");
|
|
109
|
+
}
|
|
110
|
+
this.buffer.writeUInt16LE(value, this.length);
|
|
111
|
+
this.length += 2;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* write a single 32 bit signed integer to the stream.
|
|
115
|
+
* @param value the value to write
|
|
116
|
+
*/
|
|
117
|
+
writeInteger(value) {
|
|
118
|
+
// istanbul ignore next
|
|
119
|
+
if (performCheck) {
|
|
120
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 4, "not enough space in buffer");
|
|
121
|
+
}
|
|
122
|
+
this.buffer.writeInt32LE(value, this.length);
|
|
123
|
+
this.length += 4;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* write a single 32 bit unsigned integer to the stream.
|
|
127
|
+
*
|
|
128
|
+
* @param value the value to write
|
|
129
|
+
*/
|
|
130
|
+
writeUInt32(value) {
|
|
131
|
+
// istanbul ignore next
|
|
132
|
+
if (performCheck) {
|
|
133
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 4, "not enough space in buffer");
|
|
134
|
+
(0, node_opcua_assert_1.assert)(isFinite(value));
|
|
135
|
+
(0, node_opcua_assert_1.assert)(value >= 0 && value <= MAXUINT32);
|
|
136
|
+
}
|
|
137
|
+
this.buffer.writeUInt32LE(value, this.length);
|
|
138
|
+
this.length += 4;
|
|
139
|
+
/*
|
|
140
|
+
assert(this.buffer[this.length - 4] === value % 256);
|
|
141
|
+
assert(this.buffer[this.length - 3] === (value >>> 8) % 256);
|
|
142
|
+
assert(this.buffer[this.length - 2] === (value >>> 16) % 256);
|
|
143
|
+
assert(this.buffer[this.length - 1] === (value >>> 24) % 256);
|
|
144
|
+
*/
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* write a single 32 bit floating number to the stream.
|
|
148
|
+
* @param value the value to write
|
|
149
|
+
*/
|
|
150
|
+
writeFloat(value) {
|
|
151
|
+
// istanbul ignore next
|
|
152
|
+
if (performCheck) {
|
|
153
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 4, "not enough space in buffer");
|
|
154
|
+
}
|
|
155
|
+
this.buffer.writeFloatLE(value, this.length);
|
|
156
|
+
this.length += 4;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* write a single 64 bit floating number to the stream.
|
|
160
|
+
* @param value the value to write
|
|
161
|
+
*/
|
|
162
|
+
writeDouble(value) {
|
|
163
|
+
// istanbul ignore next
|
|
164
|
+
if (performCheck) {
|
|
165
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 8, "not enough space in buffer");
|
|
166
|
+
}
|
|
167
|
+
this.buffer.writeDoubleLE(value, this.length);
|
|
168
|
+
this.length += 8;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @param arrayBuf a buffer or byte array write
|
|
172
|
+
* @param offset the offset position (default =0)
|
|
173
|
+
* @param length the number of byte to write
|
|
174
|
+
*/
|
|
175
|
+
writeArrayBuffer(arrayBuf, offset = 0, length = 0) {
|
|
176
|
+
// istanbul ignore next
|
|
177
|
+
if (performCheck) {
|
|
178
|
+
(0, node_opcua_assert_1.assert)(arrayBuf instanceof ArrayBuffer);
|
|
179
|
+
}
|
|
180
|
+
const byteArr = new Uint8Array(arrayBuf);
|
|
181
|
+
const n = (length || byteArr.length) + offset;
|
|
182
|
+
for (let i = offset; i < n; i++) {
|
|
183
|
+
this.buffer[this.length++] = byteArr[i];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// writeArrayBuffer(arrayBuf, offset, length) {
|
|
187
|
+
// offset = offset || 0;
|
|
188
|
+
//
|
|
189
|
+
// assert(arrayBuf instanceof ArrayBuffer);
|
|
190
|
+
// const byteArr = new Uint8Array(arrayBuf);
|
|
191
|
+
// length = length || byteArr.length;
|
|
192
|
+
// if (length === 0) {
|
|
193
|
+
// return;
|
|
194
|
+
// }
|
|
195
|
+
// this.length += my_memcpy(this.buffer, this.length, byteArr, offset, offset + length);
|
|
196
|
+
// }
|
|
197
|
+
/**
|
|
198
|
+
* read a single signed byte (8 bits) from the stream.
|
|
199
|
+
* @return the value read
|
|
200
|
+
*/
|
|
201
|
+
readByte() {
|
|
202
|
+
const retVal = this.buffer.readInt8(this.length);
|
|
203
|
+
this.length += 1;
|
|
204
|
+
return retVal;
|
|
205
|
+
}
|
|
206
|
+
readInt8() {
|
|
207
|
+
return this.readByte();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* read a single unsigned byte (8 bits) from the stream.
|
|
211
|
+
*/
|
|
212
|
+
readUInt8() {
|
|
213
|
+
// istanbul ignore next
|
|
214
|
+
if (performCheck) {
|
|
215
|
+
(0, node_opcua_assert_1.assert)(this.buffer.length >= this.length + 1);
|
|
216
|
+
}
|
|
217
|
+
const retVal = this.buffer.readUInt8(this.length);
|
|
218
|
+
this.length += 1;
|
|
219
|
+
return retVal;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* read a single signed 16-bit integer from the stream.
|
|
223
|
+
*/
|
|
224
|
+
readInt16() {
|
|
225
|
+
const retVal = this.buffer.readInt16LE(this.length);
|
|
226
|
+
this.length += 2;
|
|
227
|
+
return retVal;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* read a single unsigned 16-bit integer from the stream.
|
|
231
|
+
*/
|
|
232
|
+
readUInt16() {
|
|
233
|
+
const retVal = this.buffer.readUInt16LE(this.length);
|
|
234
|
+
this.length += 2;
|
|
235
|
+
return retVal;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* read a single signed 32-bit integer from the stream.
|
|
239
|
+
*/
|
|
240
|
+
readInteger() {
|
|
241
|
+
const retVal = this.buffer.readInt32LE(this.length);
|
|
242
|
+
this.length += 4;
|
|
243
|
+
return retVal;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* read a single unsigned 32-bit integer from the stream.
|
|
247
|
+
*/
|
|
248
|
+
readUInt32() {
|
|
249
|
+
const retVal = this.buffer.readUInt32LE(this.length);
|
|
250
|
+
this.length += 4;
|
|
251
|
+
return retVal;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* read a single 32-bit floating point number from the stream.
|
|
255
|
+
*/
|
|
256
|
+
readFloat() {
|
|
257
|
+
const retVal = this.buffer.readFloatLE(this.length);
|
|
258
|
+
this.length += 4;
|
|
259
|
+
return retVal;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* read a single 64-bit floating point number from the stream.
|
|
263
|
+
*/
|
|
264
|
+
readDouble() {
|
|
265
|
+
const retVal = this.buffer.readDoubleLE(this.length);
|
|
266
|
+
this.length += 8;
|
|
267
|
+
return retVal;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* write a byte stream to the stream.
|
|
271
|
+
* The method writes the length of the byte array into the stream as a 32 bits integer before the byte stream.
|
|
272
|
+
*
|
|
273
|
+
* @param buf the buffer to write.
|
|
274
|
+
*/
|
|
275
|
+
writeByteStream(buf) {
|
|
276
|
+
if (!buf) {
|
|
277
|
+
this.writeInteger(-1);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
(0, node_opcua_assert_1.assert)(buf instanceof Buffer);
|
|
281
|
+
this.writeInteger(buf.length);
|
|
282
|
+
// make sure there is enough room in destination buffer
|
|
283
|
+
const remainingBytes = this.buffer.length - this.length;
|
|
284
|
+
/* istanbul ignore next */
|
|
285
|
+
if (remainingBytes < buf.length) {
|
|
286
|
+
throw new Error("BinaryStream.writeByteStream error : not enough bytes left in buffer : bufferLength is " +
|
|
287
|
+
buf.length +
|
|
288
|
+
" but only " +
|
|
289
|
+
remainingBytes +
|
|
290
|
+
" left");
|
|
291
|
+
}
|
|
292
|
+
buf.copy(this.buffer, this.length, 0, buf.length);
|
|
293
|
+
this.length += buf.length;
|
|
294
|
+
}
|
|
295
|
+
writeString(value) {
|
|
296
|
+
if (value === undefined || value === null) {
|
|
297
|
+
this.writeUInt32(0xffffffff);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const byteLength = calculateByteLength(value);
|
|
301
|
+
this.writeInteger(byteLength);
|
|
302
|
+
if (byteLength === 0) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// make sure there is enough room in destination buffer
|
|
306
|
+
const remainingBytes = this.buffer.length - this.length;
|
|
307
|
+
/* istanbul ignore next */
|
|
308
|
+
if (remainingBytes < byteLength) {
|
|
309
|
+
throw new Error("BinaryStream.writeByteStream error : not enough bytes left in buffer : bufferLength is " +
|
|
310
|
+
byteLength +
|
|
311
|
+
" but only " +
|
|
312
|
+
remainingBytes +
|
|
313
|
+
" left");
|
|
314
|
+
}
|
|
315
|
+
this.buffer.write(value, this.length);
|
|
316
|
+
this.length += byteLength;
|
|
317
|
+
}
|
|
318
|
+
// readArrayBuffer(length: number): ArrayBuffer {
|
|
319
|
+
// assert(this.length + length <= this.buffer.length, "not enough bytes in buffer");
|
|
320
|
+
// const byteArr = new Uint8Array(new ArrayBuffer(length));
|
|
321
|
+
// my_memcpy(byteArr, 0, this.buffer, this.length, this.length + length);
|
|
322
|
+
// this.length += length;
|
|
323
|
+
// return byteArr;
|
|
324
|
+
// }
|
|
325
|
+
/**
|
|
326
|
+
* @method readArrayBuffer
|
|
327
|
+
* @param length
|
|
328
|
+
*/
|
|
329
|
+
readArrayBuffer(length) {
|
|
330
|
+
if (length > BinaryStream.maxByteStringLength) {
|
|
331
|
+
throw new Error(`maxStringLength(${BinaryStream.maxByteStringLength}) has been exceeded in BinaryStream.readArrayBuffer len=${length}`);
|
|
332
|
+
}
|
|
333
|
+
// istanbul ignore next
|
|
334
|
+
if (performCheck) {
|
|
335
|
+
(0, node_opcua_assert_1.assert)(this.length + length <= this.buffer.length, "not enough bytes in buffer");
|
|
336
|
+
}
|
|
337
|
+
const slice = this.buffer.subarray(this.length, this.length + length);
|
|
338
|
+
// istanbul ignore next
|
|
339
|
+
if (performCheck) {
|
|
340
|
+
(0, node_opcua_assert_1.assert)(slice.length === length);
|
|
341
|
+
}
|
|
342
|
+
const byteArr = new Uint8Array(slice);
|
|
343
|
+
// istanbul ignore next
|
|
344
|
+
if (performCheck) {
|
|
345
|
+
(0, node_opcua_assert_1.assert)(byteArr.length === length);
|
|
346
|
+
}
|
|
347
|
+
this.length += length;
|
|
348
|
+
return byteArr;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* read a byte stream to the stream.
|
|
352
|
+
* The method reads the length of the byte array from the stream as a 32 bits integer
|
|
353
|
+
* before reading the byte stream.
|
|
354
|
+
*
|
|
355
|
+
*/
|
|
356
|
+
readByteStream() {
|
|
357
|
+
const bufLen = this.readUInt32();
|
|
358
|
+
if (bufLen === 0xffffffff) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
if (bufLen === 0) {
|
|
362
|
+
return zeroLengthBuffer;
|
|
363
|
+
}
|
|
364
|
+
if (bufLen > BinaryStream.maxByteStringLength) {
|
|
365
|
+
throw new Error(`maxStringLength(${BinaryStream.maxByteStringLength}) has been exceeded in BinaryStream.readArrayBuffer len=${bufLen}`);
|
|
366
|
+
}
|
|
367
|
+
// check that there is enough space in the buffer
|
|
368
|
+
const remainingBytes = this.buffer.length - this.length;
|
|
369
|
+
// istanbul ignore next
|
|
370
|
+
if (remainingBytes < bufLen) {
|
|
371
|
+
throw new Error("BinaryStream.readByteStream error : not enough bytes left in buffer : bufferLength is " +
|
|
372
|
+
bufLen +
|
|
373
|
+
" but only " +
|
|
374
|
+
remainingBytes +
|
|
375
|
+
" left");
|
|
376
|
+
}
|
|
377
|
+
// create a shared memory buffer ! for speed
|
|
378
|
+
const buf = this.buffer.subarray(this.length, this.length + bufLen);
|
|
379
|
+
this.length += bufLen;
|
|
380
|
+
return buf;
|
|
381
|
+
}
|
|
382
|
+
readString() {
|
|
383
|
+
const bufLen = this.readUInt32();
|
|
384
|
+
if (bufLen === 0xffffffff) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
if (bufLen === 0) {
|
|
388
|
+
return "";
|
|
389
|
+
}
|
|
390
|
+
if (bufLen > BinaryStream.maxStringLength) {
|
|
391
|
+
throw new Error(`maxStringLength(${BinaryStream.maxStringLength}) has been exceeded in BinaryStream.readString len=${bufLen}`);
|
|
392
|
+
}
|
|
393
|
+
// check that there is enough space in the buffer
|
|
394
|
+
const remainingBytes = this.buffer.length - this.length;
|
|
395
|
+
// istanbul ignore next
|
|
396
|
+
if (remainingBytes < bufLen) {
|
|
397
|
+
throw new Error("BinaryStream.readByteStream error : not enough bytes left in buffer : bufferLength is " +
|
|
398
|
+
bufLen +
|
|
399
|
+
" but only " +
|
|
400
|
+
remainingBytes +
|
|
401
|
+
" left");
|
|
402
|
+
}
|
|
403
|
+
const str = this.buffer.toString("utf-8", this.length, this.length + bufLen);
|
|
404
|
+
this.length += bufLen;
|
|
405
|
+
return str;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
exports.BinaryStream = BinaryStream;
|
|
409
|
+
BinaryStream.maxByteStringLength = 16 * 1024 * 1024;
|
|
410
|
+
BinaryStream.maxStringLength = 16 * 1024 * 1024;
|
|
411
|
+
/**
|
|
412
|
+
* @function calculateByteLength
|
|
413
|
+
* calculate the size in bytes of a utf8 string
|
|
414
|
+
* @param str {String}
|
|
415
|
+
* @internal
|
|
416
|
+
*/
|
|
417
|
+
function calculateByteLength(str) {
|
|
418
|
+
// returns the byte length of an utf8 string
|
|
419
|
+
let s = str.length;
|
|
420
|
+
for (let i = s - 1; i >= 0; i--) {
|
|
421
|
+
const code = str.charCodeAt(i);
|
|
422
|
+
if (code > 0x7f && code <= 0x7ff) {
|
|
423
|
+
s++;
|
|
424
|
+
}
|
|
425
|
+
else if (code > 0x7ff && code <= 0xffff) {
|
|
426
|
+
s += 2;
|
|
427
|
+
}
|
|
428
|
+
if (code >= 0xdc00 && code <= 0xdfff) {
|
|
429
|
+
// trail surrogate
|
|
430
|
+
i--;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return s;
|
|
434
|
+
}
|
|
435
|
+
exports.calculateByteLength = calculateByteLength;
|
|
436
|
+
const zeroLengthBuffer = (0, node_opcua_buffer_utils_1.createFastUninitializedBuffer)(0);
|
|
437
|
+
//# sourceMappingURL=binaryStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin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-0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* a BinaryStreamSizeCalculator can be used to quickly evaluate the required size
|
|
4
|
+
* of a buffer by performing the same sequence of write operation.
|
|
5
|
+
*
|
|
6
|
+
* a BinaryStreamSizeCalculator has the same writeXXX methods as the BinaryStream stream
|
|
7
|
+
* object.
|
|
8
|
+
*
|
|
9
|
+
* @class BinaryStreamSizeCalculator
|
|
10
|
+
* @extends BinaryStream
|
|
11
|
+
* @constructor
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare class BinaryStreamSizeCalculator {
|
|
15
|
+
length: number;
|
|
16
|
+
constructor();
|
|
17
|
+
rewind(): void;
|
|
18
|
+
writeInt8(value: number): void;
|
|
19
|
+
writeUInt8(value: number): void;
|
|
20
|
+
writeInt16(value: number): void;
|
|
21
|
+
writeInteger(value: number): void;
|
|
22
|
+
writeUInt32(value: number): void;
|
|
23
|
+
writeUInt16(value: number): void;
|
|
24
|
+
writeFloat(value: number): void;
|
|
25
|
+
writeDouble(value: number): void;
|
|
26
|
+
writeArrayBuffer(arrayBuf: ArrayBuffer, offset: number, byteLength: number): void;
|
|
27
|
+
writeByteStream(buf: Buffer): void;
|
|
28
|
+
writeString(str: null | string): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinaryStreamSizeCalculator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @module node-opcua-binary-stream
|
|
6
|
+
*/
|
|
7
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
8
|
+
const binaryStream_1 = require("./binaryStream");
|
|
9
|
+
/**
|
|
10
|
+
* a BinaryStreamSizeCalculator can be used to quickly evaluate the required size
|
|
11
|
+
* of a buffer by performing the same sequence of write operation.
|
|
12
|
+
*
|
|
13
|
+
* a BinaryStreamSizeCalculator has the same writeXXX methods as the BinaryStream stream
|
|
14
|
+
* object.
|
|
15
|
+
*
|
|
16
|
+
* @class BinaryStreamSizeCalculator
|
|
17
|
+
* @extends BinaryStream
|
|
18
|
+
* @constructor
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
class BinaryStreamSizeCalculator {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.length = 0;
|
|
24
|
+
}
|
|
25
|
+
rewind() {
|
|
26
|
+
this.length = 0;
|
|
27
|
+
}
|
|
28
|
+
writeInt8(value) {
|
|
29
|
+
this.length += 1;
|
|
30
|
+
}
|
|
31
|
+
writeUInt8(value) {
|
|
32
|
+
this.length += 1;
|
|
33
|
+
}
|
|
34
|
+
writeInt16(value) {
|
|
35
|
+
this.length += 2;
|
|
36
|
+
}
|
|
37
|
+
writeInteger(value) {
|
|
38
|
+
this.length += 4;
|
|
39
|
+
}
|
|
40
|
+
writeUInt32(value) {
|
|
41
|
+
this.length += 4;
|
|
42
|
+
}
|
|
43
|
+
writeUInt16(value) {
|
|
44
|
+
this.length += 2;
|
|
45
|
+
}
|
|
46
|
+
writeFloat(value) {
|
|
47
|
+
this.length += 4;
|
|
48
|
+
}
|
|
49
|
+
writeDouble(value) {
|
|
50
|
+
this.length += 8;
|
|
51
|
+
}
|
|
52
|
+
writeArrayBuffer(arrayBuf, offset, byteLength) {
|
|
53
|
+
offset = offset || 0;
|
|
54
|
+
(0, node_opcua_assert_1.assert)(arrayBuf instanceof ArrayBuffer);
|
|
55
|
+
this.length += byteLength || arrayBuf.byteLength;
|
|
56
|
+
}
|
|
57
|
+
writeByteStream(buf) {
|
|
58
|
+
if (!buf) {
|
|
59
|
+
this.writeUInt32(0);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.writeUInt32(buf.length);
|
|
63
|
+
this.length += buf.length;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
writeString(str) {
|
|
67
|
+
if (str === undefined || str === null) {
|
|
68
|
+
this.writeUInt32(-1);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const bufLength = (0, binaryStream_1.calculateByteLength)(str);
|
|
72
|
+
this.writeUInt32(bufLength);
|
|
73
|
+
this.length += bufLength;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.BinaryStreamSizeCalculator = BinaryStreamSizeCalculator;
|
|
77
|
+
//# sourceMappingURL=binaryStreamSizeCalculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binaryStreamSizeCalculator.js","sourceRoot":"","sources":["../source/binaryStreamSizeCalculator.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAA2C;AAC3C,iDAAqD;AAErD;;;;;;;;;;;GAWG;AACH,MAAa,0BAA0B;IAInC;QACI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,CAAC;IAEM,MAAM;QACT,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IACpB,CAAC;IAEM,SAAS,CAAC,KAAa;QAC1B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,UAAU,CAAC,KAAa;QAC3B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,UAAU,CAAC,KAAa;QAC3B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,YAAY,CAAC,KAAa;QAC7B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEO,UAAU,CAAC,KAAa;QAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,WAAW,CAAC,KAAa;QAC5B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACrB,CAAC;IAEM,gBAAgB,CAAC,QAAqB,EAAE,MAAc,EAAE,UAAkB;QAC7E,MAAM,GAAG,MAAM,IAAI,CAAC,CAAC;QACrB,IAAA,0BAAM,EAAC,QAAQ,YAAY,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,IAAI,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC;IACrD,CAAC;IAEM,eAAe,CAAC,GAAW;QAC9B,IAAI,CAAC,GAAG,EAAE;YACN,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACvB;aAAM;YACH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC;SAC7B;IACL,CAAC;IAEM,WAAW,CAAC,GAAgB;QAC/B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;YACnC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;YACrB,OAAO;SACV;QACD,MAAM,SAAS,GAAG,IAAA,kCAAmB,EAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC;CACJ;AApED,gEAoEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-binary-stream
|
|
3
|
+
*/
|
|
4
|
+
import { BinaryStream } from "./binaryStream";
|
|
5
|
+
import { BinaryStreamSizeCalculator } from "./binaryStreamSizeCalculator";
|
|
6
|
+
export type OutputBinaryStream = BinaryStream | BinaryStreamSizeCalculator;
|
|
7
|
+
export * from "./binaryStream";
|
|
8
|
+
export * from "./binaryStreamSizeCalculator";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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("./binaryStream"), exports);
|
|
18
|
+
__exportStar(require("./binaryStreamSizeCalculator"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA,iDAA+B;AAC/B,+DAA6C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-binary-stream",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "pure nodejs OPCUA SDK - module
|
|
3
|
+
"version": "2.104.0",
|
|
4
|
+
"description": "pure nodejs OPCUA SDK - module binary-stream",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"lint": "eslint source/**/*.ts"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"node-opcua-assert": "2.
|
|
15
|
-
"node-opcua-buffer-utils": "2.
|
|
14
|
+
"node-opcua-assert": "2.104.0",
|
|
15
|
+
"node-opcua-buffer-utils": "2.104.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"node-opcua-benchmarker": "2.
|
|
18
|
+
"node-opcua-benchmarker": "2.104.0",
|
|
19
19
|
"should": "^13.2.3"
|
|
20
20
|
},
|
|
21
21
|
"author": "Etienne Rossignon",
|
|
@@ -33,5 +33,9 @@
|
|
|
33
33
|
"internet of things"
|
|
34
34
|
],
|
|
35
35
|
"homepage": "http://node-opcua.github.io/",
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "3cd6d355e8b3c66822d08a3ca682659ea5d1a55d",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"source"
|
|
40
|
+
]
|
|
37
41
|
}
|