node-firebird 1.1.10 → 2.0.1
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/.github/workflows/node.js.yml +45 -12
- package/0001-fix-attachEvent-host-resolution.patch +72 -0
- package/ENCRYPTION_CALLBACK.md +152 -0
- package/PR_SUMMARY.md +139 -0
- package/README.md +59 -25
- package/Roadmap.md +13 -13
- package/diff +62 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +1 -1
- package/lib/pool.js +83 -82
- package/lib/srp.js +3 -0
- package/lib/wire/connection.js +1623 -1366
- package/lib/wire/const.js +11 -5
- package/lib/wire/database.js +229 -118
- package/lib/wire/eventConnection.js +94 -92
- package/lib/wire/fbEventManager.js +107 -72
- package/lib/wire/serialize.js +434 -408
- package/lib/wire/service.js +935 -931
- package/lib/wire/socket.js +78 -3
- package/lib/wire/statement.js +32 -31
- package/lib/wire/transaction.js +135 -107
- package/lib/wire/xsqlvar.js +339 -330
- package/package.json +4 -4
- package/vitest.config.js +13 -0
package/lib/wire/serialize.js
CHANGED
|
@@ -13,135 +13,149 @@ function align(n) {
|
|
|
13
13
|
const
|
|
14
14
|
MAX_STRING_SIZE = 255;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.ensure(2);
|
|
41
|
-
this.buffer.writeUInt16LE(b, this.pos);
|
|
42
|
-
this.pos += 2;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
BlrWriter.prototype.addInt32 = function (b) {
|
|
46
|
-
this.ensure(4);
|
|
47
|
-
this.buffer.writeUInt32LE(b, this.pos);
|
|
48
|
-
this.pos += 4;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
BlrWriter.prototype.addByteInt32 = function (c, b) {
|
|
52
|
-
this.addByte(c);
|
|
53
|
-
this.ensure(4);
|
|
54
|
-
this.buffer.writeUInt32LE(b, this.pos);
|
|
55
|
-
this.pos += 4;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
BlrWriter.prototype.addNumeric = function (c, v) {
|
|
59
|
-
|
|
60
|
-
if (v < 256){
|
|
61
|
-
this.ensure(3);
|
|
62
|
-
this.buffer.writeUInt8(c, this.pos);
|
|
63
|
-
this.pos++;
|
|
64
|
-
this.buffer.writeUInt8(1, this.pos);
|
|
16
|
+
class BlrWriter {
|
|
17
|
+
constructor(size) {
|
|
18
|
+
this.buffer = Buffer.alloc(size || 32);
|
|
19
|
+
this.pos = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ensure(len) {
|
|
23
|
+
var newlen = this.buffer.length;
|
|
24
|
+
|
|
25
|
+
while (newlen < this.pos + len)
|
|
26
|
+
newlen *= 2
|
|
27
|
+
|
|
28
|
+
if (this.buffer.length >= newlen)
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
var b = Buffer.alloc(newlen);
|
|
32
|
+
this.buffer.copy(b);
|
|
33
|
+
delete(this.buffer);
|
|
34
|
+
this.buffer = b;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
addByte(b) {
|
|
38
|
+
this.ensure(1);
|
|
39
|
+
this.buffer.writeUInt8(b, this.pos);
|
|
65
40
|
this.pos++;
|
|
66
|
-
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
addShort(b) {
|
|
44
|
+
this.ensure(1);
|
|
45
|
+
this.buffer.writeInt8(b, this.pos);
|
|
67
46
|
this.pos++;
|
|
68
|
-
return;
|
|
69
47
|
}
|
|
70
48
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.buffer.writeInt32BE(v, this.pos);
|
|
77
|
-
this.pos += 4;
|
|
49
|
+
addSmall(b) {
|
|
50
|
+
this.ensure(2);
|
|
51
|
+
this.buffer.writeInt16LE(b, this.pos);
|
|
52
|
+
this.pos += 2;
|
|
53
|
+
}
|
|
78
54
|
|
|
79
|
-
|
|
55
|
+
addWord(b) {
|
|
56
|
+
this.ensure(2);
|
|
57
|
+
this.buffer.writeUInt16LE(b, this.pos);
|
|
58
|
+
this.pos += 2;
|
|
59
|
+
}
|
|
80
60
|
|
|
81
|
-
|
|
61
|
+
addInt32(b) {
|
|
62
|
+
this.ensure(4);
|
|
63
|
+
this.buffer.writeUInt32LE(b, this.pos);
|
|
64
|
+
this.pos += 4;
|
|
65
|
+
}
|
|
82
66
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
67
|
+
addByteInt32(c, b) {
|
|
68
|
+
this.addByte(c);
|
|
69
|
+
this.ensure(4);
|
|
70
|
+
this.buffer.writeUInt32LE(b, this.pos);
|
|
71
|
+
this.pos += 4;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
addNumeric(c, v) {
|
|
75
|
+
if (v < 256){
|
|
76
|
+
this.ensure(3);
|
|
77
|
+
this.buffer.writeUInt8(c, this.pos);
|
|
78
|
+
this.pos++;
|
|
79
|
+
this.buffer.writeUInt8(1, this.pos);
|
|
80
|
+
this.pos++;
|
|
81
|
+
this.buffer.writeUInt8(v, this.pos);
|
|
82
|
+
this.pos++;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.ensure(6);
|
|
87
|
+
this.buffer.writeUInt8(c, this.pos);
|
|
88
|
+
this.pos++;
|
|
89
|
+
this.buffer.writeUInt8(4, this.pos);
|
|
86
90
|
this.pos++;
|
|
91
|
+
this.buffer.writeInt32BE(v, this.pos);
|
|
92
|
+
this.pos += 4;
|
|
87
93
|
}
|
|
88
|
-
};
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
addBytes(b) {
|
|
96
|
+
this.ensure(b.length);
|
|
97
|
+
for (var i = 0, length = b.length; i < length; i++) {
|
|
98
|
+
this.buffer.writeUInt8(b[i], this.pos);
|
|
99
|
+
this.pos++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
throw new Error('blr string is too big');
|
|
103
|
+
addString(c, s, encoding) {
|
|
104
|
+
this.addByte(c);
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.buffer.write(s, this.pos, len, encoding);
|
|
101
|
-
this.pos += len;
|
|
102
|
-
};
|
|
106
|
+
var len = Buffer.byteLength(s, encoding);
|
|
107
|
+
if (len > MAX_STRING_SIZE)
|
|
108
|
+
throw new Error('blr string is too big');
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
+
this.ensure(len + 1);
|
|
111
|
+
this.buffer.writeUInt8(len, this.pos);
|
|
112
|
+
this.pos++;
|
|
113
|
+
this.buffer.write(s, this.pos, len, encoding);
|
|
114
|
+
this.pos += len;
|
|
115
|
+
}
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
addBuffer(b) {
|
|
118
|
+
this.addWord(b.length);
|
|
119
|
+
this.ensure(b.length);
|
|
120
|
+
b.copy(this.buffer, this.pos);
|
|
121
|
+
this.pos += b.length;
|
|
122
|
+
}
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
throw new Error('blr string is too big');
|
|
124
|
+
addString2(c, s, encoding) {
|
|
125
|
+
this.addByte(c);
|
|
117
126
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.buffer.write(s, this.pos, len, encoding);
|
|
122
|
-
this.pos += len;
|
|
123
|
-
};
|
|
127
|
+
var len = Buffer.byteLength(s, encoding);
|
|
128
|
+
if (len > MAX_STRING_SIZE* MAX_STRING_SIZE)
|
|
129
|
+
throw new Error('blr string is too big');
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
this.ensure(len + 2);
|
|
132
|
+
this.buffer.writeUInt16LE(len, this.pos);
|
|
133
|
+
this.pos += 2;
|
|
134
|
+
this.buffer.write(s, this.pos, len, encoding);
|
|
135
|
+
this.pos += len;
|
|
136
|
+
}
|
|
129
137
|
|
|
130
|
-
|
|
131
|
-
var
|
|
138
|
+
addMultiblockPart(c, s, encoding) {
|
|
139
|
+
var buff = Buffer.from(s, encoding);
|
|
140
|
+
var remaining = buff.length;
|
|
141
|
+
var step = 0;
|
|
132
142
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.addByte(step);
|
|
143
|
+
while (remaining > 0) {
|
|
144
|
+
var toWrite = Math.min(remaining, 254);
|
|
136
145
|
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
this.addByte(c);
|
|
147
|
+
this.addByte(toWrite + 1);
|
|
148
|
+
this.addByte(step);
|
|
139
149
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
150
|
+
this.ensure(toWrite);
|
|
151
|
+
buff.copy(this.buffer, this.pos, step * 254, (step * 254) + toWrite);
|
|
152
|
+
|
|
153
|
+
step++;
|
|
154
|
+
remaining -= toWrite;
|
|
155
|
+
this.pos += toWrite;
|
|
156
|
+
}
|
|
143
157
|
}
|
|
144
|
-
}
|
|
158
|
+
}
|
|
145
159
|
|
|
146
160
|
/***************************************
|
|
147
161
|
*
|
|
@@ -149,83 +163,83 @@ BlrWriter.prototype.addMultiblockPart = function (c, s, encoding) {
|
|
|
149
163
|
*
|
|
150
164
|
***************************************/
|
|
151
165
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
BlrReader.prototype.readByteCode = function(){
|
|
158
|
-
return this.buffer.readUInt8(this.pos++);
|
|
159
|
-
};
|
|
166
|
+
class BlrReader {
|
|
167
|
+
constructor(buffer) {
|
|
168
|
+
this.buffer = buffer;
|
|
169
|
+
this.pos = 0;
|
|
170
|
+
}
|
|
160
171
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return value;
|
|
165
|
-
}
|
|
172
|
+
readByteCode() {
|
|
173
|
+
return this.buffer.readUInt8(this.pos++);
|
|
174
|
+
}
|
|
166
175
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
switch (len) {
|
|
172
|
-
case 1:
|
|
173
|
-
value = this.buffer.readInt8(this.pos);
|
|
174
|
-
break;
|
|
175
|
-
case 2:
|
|
176
|
-
value = this.buffer.readInt16LE(this.pos);
|
|
177
|
-
break;
|
|
178
|
-
case 4:
|
|
179
|
-
value = this.buffer.readInt32LE(this.pos)
|
|
176
|
+
readInt32() {
|
|
177
|
+
var value = this.buffer.readUInt32LE(this.pos);
|
|
178
|
+
this.pos += 4;
|
|
179
|
+
return value;
|
|
180
180
|
}
|
|
181
|
-
this.pos += len;
|
|
182
|
-
return value;
|
|
183
|
-
};
|
|
184
181
|
|
|
185
|
-
|
|
182
|
+
readInt() {
|
|
183
|
+
var len = this.buffer.readUInt16LE(this.pos);
|
|
184
|
+
this.pos += 2;
|
|
185
|
+
var value;
|
|
186
|
+
switch (len) {
|
|
187
|
+
case 1:
|
|
188
|
+
value = this.buffer.readInt8(this.pos);
|
|
189
|
+
break;
|
|
190
|
+
case 2:
|
|
191
|
+
value = this.buffer.readInt16LE(this.pos);
|
|
192
|
+
break;
|
|
193
|
+
case 4:
|
|
194
|
+
value = this.buffer.readInt32LE(this.pos)
|
|
195
|
+
}
|
|
196
|
+
this.pos += len;
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
186
199
|
|
|
187
|
-
|
|
188
|
-
|
|
200
|
+
readString(encoding) {
|
|
201
|
+
var len = this.buffer.readUInt16LE(this.pos);
|
|
202
|
+
var str;
|
|
189
203
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
204
|
+
this.pos += 2;
|
|
205
|
+
if (len <= 0)
|
|
206
|
+
return '';
|
|
193
207
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
208
|
+
str = this.buffer.toString(encoding, this.pos, this.pos + len);
|
|
209
|
+
this.pos += len;
|
|
210
|
+
return str;
|
|
211
|
+
}
|
|
198
212
|
|
|
199
|
-
|
|
213
|
+
readSegment() {
|
|
214
|
+
var ret, tmp;
|
|
215
|
+
var len = this.buffer.readUInt16LE(this.pos);
|
|
200
216
|
|
|
201
|
-
|
|
202
|
-
var len = this.buffer.readUInt16LE(this.pos);
|
|
217
|
+
this.pos += 2;
|
|
203
218
|
|
|
204
|
-
|
|
219
|
+
while (len > 0) {
|
|
205
220
|
|
|
206
|
-
|
|
221
|
+
if (ret) {
|
|
222
|
+
tmp = ret;
|
|
223
|
+
ret = Buffer.alloc(tmp.length + len);
|
|
224
|
+
tmp.copy(ret);
|
|
225
|
+
this.buffer.copy(ret, tmp.length, this.pos, this.pos + len);
|
|
226
|
+
} else {
|
|
227
|
+
ret = Buffer.alloc(len);
|
|
228
|
+
this.buffer.copy(ret, 0, this.pos, this.pos + len);
|
|
229
|
+
}
|
|
207
230
|
|
|
208
|
-
|
|
209
|
-
tmp = ret;
|
|
210
|
-
ret = Buffer.alloc(tmp.length + len);
|
|
211
|
-
tmp.copy(ret);
|
|
212
|
-
this.buffer.copy(ret, tmp.length, this.pos, this.pos + len);
|
|
213
|
-
} else {
|
|
214
|
-
ret = Buffer.alloc(len);
|
|
215
|
-
this.buffer.copy(ret, 0, this.pos, this.pos + len);
|
|
216
|
-
}
|
|
231
|
+
this.pos += len;
|
|
217
232
|
|
|
218
|
-
|
|
233
|
+
if (this.pos === this.buffer.length)
|
|
234
|
+
break;
|
|
219
235
|
|
|
220
|
-
|
|
221
|
-
|
|
236
|
+
len = this.buffer.readUInt16LE(this.pos);
|
|
237
|
+
this.pos += 2;
|
|
238
|
+
}
|
|
222
239
|
|
|
223
|
-
|
|
224
|
-
this.pos += 2;
|
|
240
|
+
return ret ? ret : Buffer.alloc(0);
|
|
225
241
|
}
|
|
226
|
-
|
|
227
|
-
return ret ? ret : Buffer.alloc(0);
|
|
228
|
-
};
|
|
242
|
+
}
|
|
229
243
|
|
|
230
244
|
/***************************************
|
|
231
245
|
*
|
|
@@ -233,119 +247,121 @@ BlrReader.prototype.readSegment = function() {
|
|
|
233
247
|
*
|
|
234
248
|
***************************************/
|
|
235
249
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
newlen
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
XdrWriter.prototype.addInt128 = function (value) {
|
|
272
|
-
this.ensure(16);
|
|
273
|
-
|
|
274
|
-
const bigValue = BigInt(value);
|
|
275
|
-
|
|
276
|
-
const high = bigValue >> BigInt(64);
|
|
277
|
-
const low = bigValue & BigInt("0xFFFFFFFFFFFFFFFF");
|
|
278
|
-
|
|
279
|
-
this.buffer.writeBigUInt64BE(high, this.pos);
|
|
280
|
-
this.pos += 8;
|
|
281
|
-
this.buffer.writeBigUInt64BE(low, this.pos);
|
|
282
|
-
this.pos += 8;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
XdrWriter.prototype.addUInt = function (value) {
|
|
286
|
-
this.ensure(4);
|
|
287
|
-
this.buffer.writeUInt32BE(value, this.pos);
|
|
288
|
-
this.pos += 4;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
XdrWriter.prototype.addString = function(s, encoding) {
|
|
292
|
-
var len = Buffer.byteLength(s, encoding);
|
|
293
|
-
var alen = align(len);
|
|
294
|
-
this.ensure(alen + 4);
|
|
295
|
-
this.buffer.writeInt32BE(len, this.pos);
|
|
296
|
-
this.pos += 4;
|
|
297
|
-
this.buffer.write(s, this.pos, len, encoding);
|
|
298
|
-
this.pos += alen;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
XdrWriter.prototype.addText = function(s, encoding) {
|
|
302
|
-
var len = Buffer.byteLength(s, encoding);
|
|
303
|
-
var alen = align(len);
|
|
304
|
-
this.ensure(alen);
|
|
305
|
-
this.buffer.write(s, this.pos, len, encoding);
|
|
306
|
-
this.pos += alen;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
XdrWriter.prototype.addBlr = function(blr) {
|
|
310
|
-
var alen = align(blr.pos);
|
|
311
|
-
this.ensure(alen + 4);
|
|
312
|
-
this.buffer.writeInt32BE(blr.pos, this.pos);
|
|
313
|
-
this.pos += 4;
|
|
314
|
-
blr.buffer.copy(this.buffer, this.pos);
|
|
315
|
-
this.pos += alen;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
XdrWriter.prototype.getData = function() {
|
|
319
|
-
return this.buffer.slice(0, this.pos);
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
XdrWriter.prototype.addDouble = function(value) {
|
|
323
|
-
this.ensure(8);
|
|
324
|
-
this.buffer.writeDoubleBE(value, this.pos);
|
|
325
|
-
this.pos += 8;
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
XdrWriter.prototype.addQuad = function(quad) {
|
|
329
|
-
this.ensure(8);
|
|
330
|
-
var b = this.buffer;
|
|
331
|
-
b.writeInt32BE(quad.high, this.pos);
|
|
332
|
-
this.pos += 4;
|
|
333
|
-
b.writeInt32BE(quad.low, this.pos);
|
|
334
|
-
this.pos += 4;
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
XdrWriter.prototype.addBuffer = function(buffer) {
|
|
338
|
-
this.ensure(buffer.length);
|
|
339
|
-
buffer.copy(this.buffer, this.pos, 0, buffer.length);
|
|
340
|
-
this.pos += buffer.length;
|
|
341
|
-
}
|
|
250
|
+
class XdrWriter {
|
|
251
|
+
constructor(size) {
|
|
252
|
+
this.buffer = Buffer.alloc(size || 32);
|
|
253
|
+
this.pos = 0;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
ensure(len) {
|
|
257
|
+
var newlen = this.buffer.length;
|
|
258
|
+
|
|
259
|
+
while (newlen < this.pos + len)
|
|
260
|
+
newlen *= 2
|
|
261
|
+
|
|
262
|
+
if (this.buffer.length >= newlen)
|
|
263
|
+
return;
|
|
264
|
+
|
|
265
|
+
var b = Buffer.alloc(newlen);
|
|
266
|
+
this.buffer.copy(b);
|
|
267
|
+
delete(this.buffer);
|
|
268
|
+
this.buffer = b;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
addInt(value) {
|
|
272
|
+
this.ensure(4);
|
|
273
|
+
this.buffer.writeInt32BE(value, this.pos);
|
|
274
|
+
this.pos += 4;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
addInt64(value) {
|
|
278
|
+
this.ensure(8);
|
|
279
|
+
var l = Long.fromNumber(value);
|
|
280
|
+
this.buffer.writeInt32BE(l.high, this.pos);
|
|
281
|
+
this.pos += 4;
|
|
282
|
+
this.buffer.writeInt32BE(l.low, this.pos);
|
|
283
|
+
this.pos += 4;
|
|
284
|
+
}
|
|
342
285
|
|
|
343
|
-
|
|
344
|
-
|
|
286
|
+
addInt128(value) {
|
|
287
|
+
this.ensure(16);
|
|
345
288
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
289
|
+
const bigValue = BigInt(value);
|
|
290
|
+
|
|
291
|
+
const high = bigValue >> BigInt(64);
|
|
292
|
+
const low = bigValue & BigInt("0xFFFFFFFFFFFFFFFF");
|
|
293
|
+
|
|
294
|
+
this.buffer.writeBigUInt64BE(high, this.pos);
|
|
295
|
+
this.pos += 8;
|
|
296
|
+
this.buffer.writeBigUInt64BE(low, this.pos);
|
|
297
|
+
this.pos += 8;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
addUInt(value) {
|
|
301
|
+
this.ensure(4);
|
|
302
|
+
this.buffer.writeUInt32BE(value, this.pos);
|
|
303
|
+
this.pos += 4;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
addString(s, encoding) {
|
|
307
|
+
var len = Buffer.byteLength(s, encoding);
|
|
308
|
+
var alen = align(len);
|
|
309
|
+
this.ensure(alen + 4);
|
|
310
|
+
this.buffer.writeInt32BE(len, this.pos);
|
|
311
|
+
this.pos += 4;
|
|
312
|
+
this.buffer.write(s, this.pos, len, encoding);
|
|
313
|
+
this.pos += alen;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
addText(s, encoding) {
|
|
317
|
+
var len = Buffer.byteLength(s, encoding);
|
|
318
|
+
var alen = align(len);
|
|
319
|
+
this.ensure(alen);
|
|
320
|
+
this.buffer.write(s, this.pos, len, encoding);
|
|
321
|
+
this.pos += alen;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
addBlr(blr) {
|
|
325
|
+
var alen = align(blr.pos);
|
|
326
|
+
this.ensure(alen + 4);
|
|
327
|
+
this.buffer.writeInt32BE(blr.pos, this.pos);
|
|
328
|
+
this.pos += 4;
|
|
329
|
+
blr.buffer.copy(this.buffer, this.pos);
|
|
330
|
+
this.pos += alen;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
getData() {
|
|
334
|
+
return this.buffer.slice(0, this.pos);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
addDouble(value) {
|
|
338
|
+
this.ensure(8);
|
|
339
|
+
this.buffer.writeDoubleBE(value, this.pos);
|
|
340
|
+
this.pos += 8;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
addQuad(quad) {
|
|
344
|
+
this.ensure(8);
|
|
345
|
+
var b = this.buffer;
|
|
346
|
+
b.writeInt32BE(quad.high, this.pos);
|
|
347
|
+
this.pos += 4;
|
|
348
|
+
b.writeInt32BE(quad.low, this.pos);
|
|
349
|
+
this.pos += 4;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
addBuffer(buffer) {
|
|
353
|
+
this.ensure(buffer.length);
|
|
354
|
+
buffer.copy(this.buffer, this.pos, 0, buffer.length);
|
|
355
|
+
this.pos += buffer.length;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
addAlignment(len) {
|
|
359
|
+
var alen = (4 - len) & 3;
|
|
360
|
+
|
|
361
|
+
this.ensure(alen);
|
|
362
|
+
this.buffer.write('ffffff', this.pos, alen, 'hex');
|
|
363
|
+
this.pos += alen;
|
|
364
|
+
}
|
|
349
365
|
}
|
|
350
366
|
|
|
351
367
|
/***************************************
|
|
@@ -354,107 +370,109 @@ XdrWriter.prototype.addAlignment = function(len) {
|
|
|
354
370
|
*
|
|
355
371
|
***************************************/
|
|
356
372
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
XdrReader.prototype.readUInt = function () {
|
|
369
|
-
var r = this.buffer.readUInt32BE(this.pos);
|
|
370
|
-
this.pos += 4;
|
|
371
|
-
return r;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
XdrReader.prototype.readInt64 = function () {
|
|
375
|
-
var high = this.buffer.readInt32BE(this.pos);
|
|
376
|
-
this.pos += 4;
|
|
377
|
-
var low = this.buffer.readInt32BE(this.pos);
|
|
378
|
-
this.pos += 4;
|
|
379
|
-
return new Long(low, high).toNumber();
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
XdrReader.prototype.readInt128 = function () {
|
|
383
|
-
var high = this.buffer.readBigUInt64BE(this.pos)
|
|
384
|
-
this.pos += 8
|
|
385
|
-
|
|
386
|
-
var low = this.buffer.readBigUInt64BE(this.pos)
|
|
387
|
-
this.pos += 8
|
|
388
|
-
|
|
389
|
-
return (BigInt(high) << BigInt(64)) + BigInt(low)
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
XdrReader.prototype.readShort = function () {
|
|
393
|
-
var r = this.buffer.readInt16BE(this.pos);
|
|
394
|
-
this.pos += 2;
|
|
395
|
-
return r;
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
XdrReader.prototype.readQuad = function () {
|
|
399
|
-
var b = this.buffer;
|
|
400
|
-
var high = b.readInt32BE(this.pos);
|
|
401
|
-
this.pos += 4;
|
|
402
|
-
var low = b.readInt32BE(this.pos);
|
|
403
|
-
this.pos += 4;
|
|
404
|
-
return {low: low, high: high}
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
XdrReader.prototype.readFloat = function () {
|
|
408
|
-
var r = this.buffer.readFloatBE(this.pos);
|
|
409
|
-
this.pos += 4;
|
|
410
|
-
return r;
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
XdrReader.prototype.readDouble = function () {
|
|
414
|
-
var r = this.buffer.readDoubleBE(this.pos);
|
|
415
|
-
this.pos += 8;
|
|
416
|
-
return r;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
XdrReader.prototype.readArray = function () {
|
|
420
|
-
var len = this.readInt();
|
|
421
|
-
if (!len)
|
|
422
|
-
return;
|
|
423
|
-
var r = this.buffer.slice(this.pos, this.pos + len);
|
|
424
|
-
this.pos += align(len);
|
|
425
|
-
return r;
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
XdrReader.prototype.readBuffer = function (len, toAlign = true) {
|
|
429
|
-
if (!arguments.length) {
|
|
430
|
-
len = this.readInt();
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (len !== null && len !== undefined) {
|
|
434
|
-
|
|
435
|
-
if (len <= 0){
|
|
436
|
-
return Buffer.alloc(0);
|
|
437
|
-
}
|
|
373
|
+
class XdrReader {
|
|
374
|
+
constructor(buffer) {
|
|
375
|
+
this.buffer = buffer;
|
|
376
|
+
this.pos = 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
readInt() {
|
|
380
|
+
var r = this.buffer.readInt32BE(this.pos);
|
|
381
|
+
this.pos += 4;
|
|
382
|
+
return r;
|
|
383
|
+
}
|
|
438
384
|
|
|
385
|
+
readUInt() {
|
|
386
|
+
var r = this.buffer.readUInt32BE(this.pos);
|
|
387
|
+
this.pos += 4;
|
|
388
|
+
return r;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
readInt64() {
|
|
392
|
+
var high = this.buffer.readInt32BE(this.pos);
|
|
393
|
+
this.pos += 4;
|
|
394
|
+
var low = this.buffer.readInt32BE(this.pos);
|
|
395
|
+
this.pos += 4;
|
|
396
|
+
return new Long(low, high).toNumber();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
readInt128() {
|
|
400
|
+
var high = this.buffer.readBigUInt64BE(this.pos)
|
|
401
|
+
this.pos += 8
|
|
402
|
+
|
|
403
|
+
var low = this.buffer.readBigUInt64BE(this.pos)
|
|
404
|
+
this.pos += 8
|
|
405
|
+
|
|
406
|
+
return (BigInt(high) << BigInt(64)) + BigInt(low)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
readShort() {
|
|
410
|
+
var r = this.buffer.readInt16BE(this.pos);
|
|
411
|
+
this.pos += 2;
|
|
412
|
+
return r;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
readQuad() {
|
|
416
|
+
var b = this.buffer;
|
|
417
|
+
var high = b.readInt32BE(this.pos);
|
|
418
|
+
this.pos += 4;
|
|
419
|
+
var low = b.readInt32BE(this.pos);
|
|
420
|
+
this.pos += 4;
|
|
421
|
+
return {low: low, high: high}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
readFloat() {
|
|
425
|
+
var r = this.buffer.readFloatBE(this.pos);
|
|
426
|
+
this.pos += 4;
|
|
427
|
+
return r;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
readDouble() {
|
|
431
|
+
var r = this.buffer.readDoubleBE(this.pos);
|
|
432
|
+
this.pos += 8;
|
|
433
|
+
return r;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
readArray() {
|
|
437
|
+
var len = this.readInt();
|
|
438
|
+
if (!len)
|
|
439
|
+
return;
|
|
439
440
|
var r = this.buffer.slice(this.pos, this.pos + len);
|
|
440
|
-
this.pos +=
|
|
441
|
+
this.pos += align(len);
|
|
441
442
|
return r;
|
|
442
443
|
}
|
|
443
|
-
};
|
|
444
444
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
445
|
+
readBuffer(len, toAlign = true) {
|
|
446
|
+
if (!arguments.length) {
|
|
447
|
+
len = this.readInt();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (len !== null && len !== undefined) {
|
|
451
|
+
|
|
452
|
+
if (len <= 0){
|
|
453
|
+
return Buffer.alloc(0);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
var r = this.buffer.slice(this.pos, this.pos + len);
|
|
457
|
+
this.pos += toAlign ? align(len) : len;
|
|
458
|
+
return r;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
readString(encoding) {
|
|
463
|
+
var len = this.readInt();
|
|
464
|
+
return this.readText(len, encoding);
|
|
465
|
+
}
|
|
449
466
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
467
|
+
readText(len, encoding) {
|
|
468
|
+
if (len <= 0)
|
|
469
|
+
return '';
|
|
453
470
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
471
|
+
var r = this.buffer.toString(encoding, this.pos, this.pos + len);
|
|
472
|
+
this.pos += align(len);
|
|
473
|
+
return r;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
458
476
|
|
|
459
477
|
/***************************************
|
|
460
478
|
*
|
|
@@ -466,57 +484,65 @@ var BUFFER_BITS = 8;
|
|
|
466
484
|
var BIT_ON = 1;
|
|
467
485
|
var BIT_OFF = 0;
|
|
468
486
|
|
|
469
|
-
|
|
470
|
-
|
|
487
|
+
class BitSet {
|
|
488
|
+
constructor(buffer) {
|
|
489
|
+
this.data = [];
|
|
471
490
|
|
|
472
|
-
|
|
473
|
-
|
|
491
|
+
if (buffer) {
|
|
492
|
+
this.scale(buffer.length * BUFFER_BITS);
|
|
474
493
|
|
|
475
|
-
|
|
476
|
-
|
|
494
|
+
for (var i = 0; i < buffer.length; i++) {
|
|
495
|
+
var n = buffer[i];
|
|
477
496
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
497
|
+
for (var j = 0; j < BUFFER_BITS; j++) {
|
|
498
|
+
var k = i * BUFFER_BITS + j;
|
|
499
|
+
this.data[k >>> WORD_LOG] |= (n >> j & BIT_ON) << k;
|
|
500
|
+
}
|
|
481
501
|
}
|
|
482
502
|
}
|
|
483
503
|
}
|
|
484
|
-
};
|
|
485
504
|
|
|
486
|
-
|
|
487
|
-
|
|
505
|
+
scale(index) {
|
|
506
|
+
var l = index >>> WORD_LOG;
|
|
488
507
|
|
|
489
|
-
|
|
490
|
-
|
|
508
|
+
for (var i = this.data.length; l >= i; l--) {
|
|
509
|
+
this.data.push(BIT_OFF);
|
|
510
|
+
}
|
|
491
511
|
}
|
|
492
|
-
};
|
|
493
512
|
|
|
494
|
-
|
|
495
|
-
|
|
513
|
+
set(index, value) {
|
|
514
|
+
let pos = index >>> 3;
|
|
496
515
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
516
|
+
for (let i = this.data.length; pos >= i; pos--) {
|
|
517
|
+
this.data.push(BIT_OFF);
|
|
518
|
+
}
|
|
500
519
|
|
|
501
|
-
|
|
520
|
+
pos = index >>> 3;
|
|
502
521
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
522
|
+
if (value === undefined || value) {
|
|
523
|
+
this.data[pos] |= (1 << (index % BUFFER_BITS));
|
|
524
|
+
} else {
|
|
525
|
+
this.data[pos] &= ~(1 << (index % BUFFER_BITS));
|
|
526
|
+
}
|
|
507
527
|
}
|
|
508
|
-
};
|
|
509
528
|
|
|
510
|
-
|
|
511
|
-
|
|
529
|
+
get(index) {
|
|
530
|
+
var n = index >>> WORD_LOG;
|
|
512
531
|
|
|
513
|
-
|
|
514
|
-
|
|
532
|
+
if (n >= this.data.length) {
|
|
533
|
+
return BIT_OFF;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return (this.data[n] >>> index) & BIT_ON;
|
|
515
537
|
}
|
|
516
538
|
|
|
517
|
-
|
|
518
|
-
|
|
539
|
+
toBuffer() {
|
|
540
|
+
return Buffer.from(this.data);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
519
543
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
544
|
+
exports.BlrWriter = BlrWriter;
|
|
545
|
+
exports.BlrReader = BlrReader;
|
|
546
|
+
exports.XdrWriter = XdrWriter;
|
|
547
|
+
exports.XdrReader = XdrReader;
|
|
548
|
+
exports.BitSet = BitSet;
|