tedious 1.12.3 → 1.14.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/README.md +1 -1
- package/appveyor.yml +9 -5
- package/benchmarks/README.md +33 -0
- package/benchmarks/common.js +82 -0
- package/benchmarks/index.js +34 -0
- package/benchmarks/query/many-result-rows.js +49 -0
- package/benchmarks/query/nvarchar-large.js +44 -0
- package/benchmarks/query/nvarchar-small.js +44 -0
- package/benchmarks/query/varbinary-4.js +42 -0
- package/benchmarks/query/varbinary-huge.js +46 -0
- package/benchmarks/query/varbinary-large.js +46 -0
- package/benchmarks/query/varbinary-small.js +42 -0
- package/benchmarks/token-parser/colmetadata-token.js +42 -0
- package/benchmarks/token-parser/done-token.js +42 -0
- package/benchmarks/token-parser/simple-tokens.js +366 -0
- package/lib/all-headers.js +9 -11
- package/lib/buffertools.js +17 -13
- package/lib/bulk-load.js +196 -169
- package/lib/collation.js +80 -2
- package/lib/connection.js +1086 -1060
- package/lib/data-type.js +450 -253
- package/lib/debug.js +57 -51
- package/lib/errors.js +40 -55
- package/lib/guid-parser.js +12 -36
- package/lib/instance-lookup.js +57 -54
- package/lib/library.js +3 -2
- package/lib/login7-payload.js +187 -180
- package/lib/message-io.js +169 -199
- package/lib/metadata-parser.js +169 -255
- package/lib/ntlm-payload.js +173 -160
- package/lib/packet.js +166 -152
- package/lib/prelogin-payload.js +170 -160
- package/lib/request.js +122 -122
- package/lib/rpcrequest-payload.js +64 -38
- package/lib/special-stored-procedure.js +3 -2
- package/lib/sqlbatch-payload.js +20 -16
- package/lib/stream-parser.js +116 -104
- package/lib/tds-versions.js +5 -8
- package/lib/tedious.js +8 -14
- package/lib/token/colmetadata-token-parser.js +79 -125
- package/lib/token/done-token-parser.js +47 -129
- package/lib/token/env-change-token-parser.js +90 -126
- package/lib/token/infoerror-token-parser.js +47 -125
- package/lib/token/loginack-token-parser.js +36 -74
- package/lib/token/nbcrow-token-parser.js +40 -64
- package/lib/token/order-token-parser.js +26 -43
- package/lib/token/returnstatus-token-parser.js +11 -23
- package/lib/token/returnvalue-token-parser.js +31 -54
- package/lib/token/row-token-parser.js +39 -52
- package/lib/token/sspi-token-parser.js +14 -32
- package/lib/token/stream-parser.js +424 -304
- package/lib/token/token-stream-parser.js +39 -34
- package/lib/token/token.js +3 -6
- package/lib/tracking-buffer/bigint.js +45 -48
- package/lib/tracking-buffer/readable-tracking-buffer.js +238 -223
- package/lib/tracking-buffer/tracking-buffer.js +3 -9
- package/lib/tracking-buffer/writable-tracking-buffer.js +272 -244
- package/lib/transaction.js +112 -102
- package/lib/value-parser.js +559 -1154
- package/package.json +10 -9
- package/benchmarks/benchmarks.coffee +0 -122
- package/benchmarks/query.coffee +0 -57
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
var SHIFT_LEFT_32, SHIFT_RIGHT_32, UNKNOWN_PLP_LEN, WritableTrackingBuffer, bigint, buffertools;
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
var _createClass = require('babel-runtime/helpers/create-class')['default'];
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
var bigint = require('./bigint');
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
require('../buffertools');
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
12
|
+
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
13
|
+
var UNKNOWN_PLP_LEN = new Buffer([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
|
|
13
14
|
|
|
14
15
|
/*
|
|
15
16
|
A Buffer-like class that tracks position.
|
|
@@ -17,272 +18,299 @@ UNKNOWN_PLP_LEN = new Buffer([0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
|
|
|
17
18
|
As values are written, the position advances by the size of the written data.
|
|
18
19
|
When writing, automatically allocates new buffers if there's not enough space.
|
|
19
20
|
*/
|
|
21
|
+
module.exports = (function () {
|
|
22
|
+
function WritableTrackingBuffer(initialSize, encoding, doubleSizeGrowth) {
|
|
23
|
+
_classCallCheck(this, WritableTrackingBuffer);
|
|
20
24
|
|
|
21
|
-
WritableTrackingBuffer = (function () {
|
|
22
|
-
function WritableTrackingBuffer(initialSize, encoding1, doubleSizeGrowth) {
|
|
23
25
|
this.initialSize = initialSize;
|
|
24
|
-
this.encoding =
|
|
26
|
+
this.encoding = encoding;
|
|
25
27
|
this.doubleSizeGrowth = doubleSizeGrowth;
|
|
26
28
|
this.doubleSizeGrowth || (this.doubleSizeGrowth = false);
|
|
27
29
|
this.encoding || (this.encoding = 'ucs2');
|
|
28
30
|
this.buffer = new Buffer(this.initialSize);
|
|
29
31
|
this.position = 0;
|
|
30
|
-
this.__defineGetter__("data", function () {
|
|
31
|
-
this.newBuffer(0);
|
|
32
|
-
return this.compositeBuffer;
|
|
33
|
-
});
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
WritableTrackingBuffer
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (this.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
size
|
|
34
|
+
_createClass(WritableTrackingBuffer, [{
|
|
35
|
+
key: 'copyFrom',
|
|
36
|
+
value: function copyFrom(buffer) {
|
|
37
|
+
var length = buffer.length;
|
|
38
|
+
this.makeRoomFor(length);
|
|
39
|
+
buffer.copy(this.buffer, this.position);
|
|
40
|
+
return this.position += length;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: 'makeRoomFor',
|
|
44
|
+
value: function makeRoomFor(requiredLength) {
|
|
45
|
+
if (this.buffer.length - this.position < requiredLength) {
|
|
46
|
+
if (this.doubleSizeGrowth) {
|
|
47
|
+
var size = this.buffer.length * 2;
|
|
48
|
+
while (size < requiredLength) {
|
|
49
|
+
size *= 2;
|
|
50
|
+
}
|
|
51
|
+
return this.newBuffer(size);
|
|
52
|
+
} else {
|
|
53
|
+
return this.newBuffer(requiredLength);
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: 'newBuffer',
|
|
59
|
+
value: function newBuffer(size) {
|
|
60
|
+
size || (size = this.initialSize);
|
|
61
|
+
var buffer = this.buffer.slice(0, this.position);
|
|
62
|
+
if (this.compositeBuffer) {
|
|
63
|
+
this.compositeBuffer = Buffer.concat([this.compositeBuffer, buffer]);
|
|
53
64
|
} else {
|
|
54
|
-
|
|
65
|
+
this.compositeBuffer = buffer;
|
|
55
66
|
}
|
|
67
|
+
this.buffer = new Buffer(size);
|
|
68
|
+
return this.position = 0;
|
|
56
69
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.compositeBuffer = Buffer.concat([this.compositeBuffer, buffer]);
|
|
65
|
-
} else {
|
|
66
|
-
this.compositeBuffer = buffer;
|
|
70
|
+
}, {
|
|
71
|
+
key: 'writeUInt8',
|
|
72
|
+
value: function writeUInt8(value) {
|
|
73
|
+
var length = 1;
|
|
74
|
+
this.makeRoomFor(length);
|
|
75
|
+
this.buffer.writeUInt8(value, this.position);
|
|
76
|
+
return this.position += length;
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
WritableTrackingBuffer.prototype.writeUInt16LE = function (value) {
|
|
81
|
-
var length;
|
|
82
|
-
length = 2;
|
|
83
|
-
this.makeRoomFor(length);
|
|
84
|
-
this.buffer.writeUInt16LE(value, this.position);
|
|
85
|
-
return this.position += length;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
WritableTrackingBuffer.prototype.writeUShort = function (value) {
|
|
89
|
-
return this.writeUInt16LE(value);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
WritableTrackingBuffer.prototype.writeUInt16BE = function (value) {
|
|
93
|
-
var length;
|
|
94
|
-
length = 2;
|
|
95
|
-
this.makeRoomFor(length);
|
|
96
|
-
this.buffer.writeUInt16BE(value, this.position);
|
|
97
|
-
return this.position += length;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
WritableTrackingBuffer.prototype.writeUInt24LE = function (value) {
|
|
101
|
-
var length;
|
|
102
|
-
length = 3;
|
|
103
|
-
this.makeRoomFor(length);
|
|
104
|
-
this.buffer[this.position + 2] = value >>> 16 & 0xff;
|
|
105
|
-
this.buffer[this.position + 1] = value >>> 8 & 0xff;
|
|
106
|
-
this.buffer[this.position] = value & 0xff;
|
|
107
|
-
return this.position += length;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
WritableTrackingBuffer.prototype.writeUInt32LE = function (value) {
|
|
111
|
-
var length;
|
|
112
|
-
length = 4;
|
|
113
|
-
this.makeRoomFor(length);
|
|
114
|
-
this.buffer.writeUInt32LE(value, this.position);
|
|
115
|
-
return this.position += length;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
WritableTrackingBuffer.prototype.writeUInt64LE = function (value) {
|
|
119
|
-
var high, low;
|
|
120
|
-
low = value % 0x100000000;
|
|
121
|
-
high = Math.floor(value / 0x100000000);
|
|
122
|
-
this.writeUInt32LE(low);
|
|
123
|
-
return this.writeUInt32LE(high);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
WritableTrackingBuffer.prototype.writeInt64LE = function (value) {
|
|
127
|
-
var buf;
|
|
128
|
-
buf = bigint.numberToInt64LE(value);
|
|
129
|
-
return this.copyFrom(buf);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
WritableTrackingBuffer.prototype.writeUInt32BE = function (value) {
|
|
133
|
-
var length;
|
|
134
|
-
length = 4;
|
|
135
|
-
this.makeRoomFor(length);
|
|
136
|
-
this.buffer.writeUInt32BE(value, this.position);
|
|
137
|
-
return this.position += length;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
WritableTrackingBuffer.prototype.writeUInt40LE = function (value) {
|
|
141
|
-
this.writeInt32LE(value & -1);
|
|
142
|
-
return this.writeUInt8(Math.floor(value * SHIFT_RIGHT_32));
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
WritableTrackingBuffer.prototype.writeUInt64LE = function (value) {
|
|
146
|
-
this.writeInt32LE(value & -1);
|
|
147
|
-
return this.writeUInt32LE(Math.floor(value * SHIFT_RIGHT_32));
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
WritableTrackingBuffer.prototype.writeInt8 = function (value) {
|
|
151
|
-
var length;
|
|
152
|
-
length = 1;
|
|
153
|
-
this.makeRoomFor(length);
|
|
154
|
-
this.buffer.writeInt8(value, this.position);
|
|
155
|
-
return this.position += length;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
WritableTrackingBuffer.prototype.writeInt16LE = function (value) {
|
|
159
|
-
var length;
|
|
160
|
-
length = 2;
|
|
161
|
-
this.makeRoomFor(length);
|
|
162
|
-
this.buffer.writeInt16LE(value, this.position);
|
|
163
|
-
return this.position += length;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
WritableTrackingBuffer.prototype.writeInt16BE = function (value) {
|
|
167
|
-
var length;
|
|
168
|
-
length = 2;
|
|
169
|
-
this.makeRoomFor(length);
|
|
170
|
-
this.buffer.writeInt16BE(value, this.position);
|
|
171
|
-
return this.position += length;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
WritableTrackingBuffer.prototype.writeInt32LE = function (value) {
|
|
175
|
-
var length;
|
|
176
|
-
length = 4;
|
|
177
|
-
this.makeRoomFor(length);
|
|
178
|
-
this.buffer.writeInt32LE(value, this.position);
|
|
179
|
-
return this.position += length;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
WritableTrackingBuffer.prototype.writeInt32BE = function (value) {
|
|
183
|
-
var length;
|
|
184
|
-
length = 4;
|
|
185
|
-
this.makeRoomFor(length);
|
|
186
|
-
this.buffer.writeInt32BE(value, this.position);
|
|
187
|
-
return this.position += length;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
WritableTrackingBuffer.prototype.writeFloatLE = function (value) {
|
|
191
|
-
var length;
|
|
192
|
-
length = 4;
|
|
193
|
-
this.makeRoomFor(length);
|
|
194
|
-
this.buffer.writeFloatLE(value, this.position);
|
|
195
|
-
return this.position += length;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
WritableTrackingBuffer.prototype.writeDoubleLE = function (value) {
|
|
199
|
-
var length;
|
|
200
|
-
length = 8;
|
|
201
|
-
this.makeRoomFor(length);
|
|
202
|
-
this.buffer.writeDoubleLE(value, this.position);
|
|
203
|
-
return this.position += length;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
WritableTrackingBuffer.prototype.writeString = function (value, encoding) {
|
|
207
|
-
var bytesWritten, length;
|
|
208
|
-
encoding || (encoding = this.encoding);
|
|
209
|
-
length = Buffer.byteLength(value, encoding);
|
|
210
|
-
this.makeRoomFor(length);
|
|
211
|
-
bytesWritten = this.buffer.write(value, this.position, encoding);
|
|
212
|
-
this.position += length;
|
|
213
|
-
return bytesWritten;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
WritableTrackingBuffer.prototype.writeBVarchar = function (value, encoding) {
|
|
217
|
-
this.writeUInt8(value.length);
|
|
218
|
-
return this.writeString(value, encoding);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
WritableTrackingBuffer.prototype.writeUsVarchar = function (value, encoding) {
|
|
222
|
-
this.writeUInt16LE(value.length);
|
|
223
|
-
return this.writeString(value, encoding);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
WritableTrackingBuffer.prototype.writeUsVarbyte = function (value, encoding) {
|
|
227
|
-
var length;
|
|
228
|
-
if (encoding == null) {
|
|
229
|
-
encoding = this.encoding;
|
|
78
|
+
}, {
|
|
79
|
+
key: 'writeUInt16LE',
|
|
80
|
+
value: function writeUInt16LE(value) {
|
|
81
|
+
var length = 2;
|
|
82
|
+
this.makeRoomFor(length);
|
|
83
|
+
this.buffer.writeUInt16LE(value, this.position);
|
|
84
|
+
return this.position += length;
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: 'writeUShort',
|
|
88
|
+
value: function writeUShort(value) {
|
|
89
|
+
return this.writeUInt16LE(value);
|
|
230
90
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
91
|
+
}, {
|
|
92
|
+
key: 'writeUInt16BE',
|
|
93
|
+
value: function writeUInt16BE(value) {
|
|
94
|
+
var length = 2;
|
|
95
|
+
this.makeRoomFor(length);
|
|
96
|
+
this.buffer.writeUInt16BE(value, this.position);
|
|
97
|
+
return this.position += length;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: 'writeUInt24LE',
|
|
101
|
+
value: function writeUInt24LE(value) {
|
|
102
|
+
var length = 3;
|
|
103
|
+
this.makeRoomFor(length);
|
|
104
|
+
this.buffer[this.position + 2] = value >>> 16 & 0xff;
|
|
105
|
+
this.buffer[this.position + 1] = value >>> 8 & 0xff;
|
|
106
|
+
this.buffer[this.position] = value & 0xff;
|
|
107
|
+
return this.position += length;
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: 'writeUInt32LE',
|
|
111
|
+
value: function writeUInt32LE(value) {
|
|
112
|
+
var length = 4;
|
|
113
|
+
this.makeRoomFor(length);
|
|
114
|
+
this.buffer.writeUInt32LE(value, this.position);
|
|
115
|
+
return this.position += length;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: 'writeUInt64LE',
|
|
119
|
+
value: function writeUInt64LE(value) {
|
|
120
|
+
var low = value % 0x100000000;
|
|
121
|
+
var high = Math.floor(value / 0x100000000);
|
|
122
|
+
this.writeUInt32LE(low);
|
|
123
|
+
return this.writeUInt32LE(high);
|
|
236
124
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
125
|
+
}, {
|
|
126
|
+
key: 'writeInt64LE',
|
|
127
|
+
value: function writeInt64LE(value) {
|
|
128
|
+
var buf = bigint.numberToInt64LE(value);
|
|
129
|
+
return this.copyFrom(buf);
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
key: 'writeUInt32BE',
|
|
133
|
+
value: function writeUInt32BE(value) {
|
|
134
|
+
var length = 4;
|
|
241
135
|
this.makeRoomFor(length);
|
|
242
|
-
this.buffer.
|
|
136
|
+
this.buffer.writeUInt32BE(value, this.position);
|
|
243
137
|
return this.position += length;
|
|
244
138
|
}
|
|
245
|
-
}
|
|
139
|
+
}, {
|
|
140
|
+
key: 'writeUInt40LE',
|
|
141
|
+
value: function writeUInt40LE(value) {
|
|
142
|
+
// inspired by https://github.com/dpw/node-buffer-more-ints
|
|
143
|
+
this.writeInt32LE(value & -1);
|
|
144
|
+
return this.writeUInt8(Math.floor(value * SHIFT_RIGHT_32));
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: 'writeUInt64LE',
|
|
148
|
+
value: function writeUInt64LE(value) {
|
|
149
|
+
this.writeInt32LE(value & -1);
|
|
150
|
+
return this.writeUInt32LE(Math.floor(value * SHIFT_RIGHT_32));
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: 'writeInt8',
|
|
154
|
+
value: function writeInt8(value) {
|
|
155
|
+
var length = 1;
|
|
156
|
+
this.makeRoomFor(length);
|
|
157
|
+
this.buffer.writeInt8(value, this.position);
|
|
158
|
+
return this.position += length;
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
key: 'writeInt16LE',
|
|
162
|
+
value: function writeInt16LE(value) {
|
|
163
|
+
var length = 2;
|
|
164
|
+
this.makeRoomFor(length);
|
|
165
|
+
this.buffer.writeInt16LE(value, this.position);
|
|
166
|
+
return this.position += length;
|
|
167
|
+
}
|
|
168
|
+
}, {
|
|
169
|
+
key: 'writeInt16BE',
|
|
170
|
+
value: function writeInt16BE(value) {
|
|
171
|
+
var length = 2;
|
|
172
|
+
this.makeRoomFor(length);
|
|
173
|
+
this.buffer.writeInt16BE(value, this.position);
|
|
174
|
+
return this.position += length;
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: 'writeInt32LE',
|
|
178
|
+
value: function writeInt32LE(value) {
|
|
179
|
+
var length = 4;
|
|
180
|
+
this.makeRoomFor(length);
|
|
181
|
+
this.buffer.writeInt32LE(value, this.position);
|
|
182
|
+
return this.position += length;
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
key: 'writeInt32BE',
|
|
186
|
+
value: function writeInt32BE(value) {
|
|
187
|
+
var length = 4;
|
|
188
|
+
this.makeRoomFor(length);
|
|
189
|
+
this.buffer.writeInt32BE(value, this.position);
|
|
190
|
+
return this.position += length;
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: 'writeFloatLE',
|
|
194
|
+
value: function writeFloatLE(value) {
|
|
195
|
+
var length = 4;
|
|
196
|
+
this.makeRoomFor(length);
|
|
197
|
+
this.buffer.writeFloatLE(value, this.position);
|
|
198
|
+
return this.position += length;
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: 'writeDoubleLE',
|
|
202
|
+
value: function writeDoubleLE(value) {
|
|
203
|
+
var length = 8;
|
|
204
|
+
this.makeRoomFor(length);
|
|
205
|
+
this.buffer.writeDoubleLE(value, this.position);
|
|
206
|
+
return this.position += length;
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: 'writeString',
|
|
210
|
+
value: function writeString(value, encoding) {
|
|
211
|
+
encoding || (encoding = this.encoding);
|
|
212
|
+
|
|
213
|
+
var length = Buffer.byteLength(value, encoding);
|
|
214
|
+
this.makeRoomFor(length);
|
|
215
|
+
|
|
216
|
+
var bytesWritten = this.buffer.write(value, this.position, encoding);
|
|
217
|
+
this.position += length;
|
|
246
218
|
|
|
247
|
-
|
|
248
|
-
var length;
|
|
249
|
-
if (encoding == null) {
|
|
250
|
-
encoding = this.encoding;
|
|
219
|
+
return bytesWritten;
|
|
251
220
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
value
|
|
256
|
-
|
|
221
|
+
}, {
|
|
222
|
+
key: 'writeBVarchar',
|
|
223
|
+
value: function writeBVarchar(value, encoding) {
|
|
224
|
+
this.writeUInt8(value.length);
|
|
225
|
+
return this.writeString(value, encoding);
|
|
257
226
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
227
|
+
}, {
|
|
228
|
+
key: 'writeUsVarchar',
|
|
229
|
+
value: function writeUsVarchar(value, encoding) {
|
|
230
|
+
this.writeUInt16LE(value.length);
|
|
231
|
+
return this.writeString(value, encoding);
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: 'writeUsVarbyte',
|
|
235
|
+
value: function writeUsVarbyte(value, encoding) {
|
|
236
|
+
if (encoding == null) {
|
|
237
|
+
encoding = this.encoding;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var length = undefined;
|
|
241
|
+
if (Buffer.isBuffer(value)) {
|
|
242
|
+
length = value.length;
|
|
243
|
+
} else {
|
|
244
|
+
value = value.toString();
|
|
245
|
+
length = Buffer.byteLength(value, encoding);
|
|
246
|
+
}
|
|
247
|
+
this.writeUInt16LE(length);
|
|
248
|
+
|
|
261
249
|
if (Buffer.isBuffer(value)) {
|
|
262
|
-
this.writeBuffer(value);
|
|
250
|
+
return this.writeBuffer(value);
|
|
263
251
|
} else {
|
|
264
252
|
this.makeRoomFor(length);
|
|
265
253
|
this.buffer.write(value, this.position, encoding);
|
|
266
|
-
this.position += length;
|
|
254
|
+
return this.position += length;
|
|
267
255
|
}
|
|
268
256
|
}
|
|
269
|
-
|
|
270
|
-
|
|
257
|
+
}, {
|
|
258
|
+
key: 'writePLPBody',
|
|
259
|
+
value: function writePLPBody(value, encoding) {
|
|
260
|
+
if (encoding == null) {
|
|
261
|
+
encoding = this.encoding;
|
|
262
|
+
}
|
|
271
263
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
264
|
+
var length = undefined;
|
|
265
|
+
if (Buffer.isBuffer(value)) {
|
|
266
|
+
length = value.length;
|
|
267
|
+
} else {
|
|
268
|
+
value = value.toString();
|
|
269
|
+
length = Buffer.byteLength(value, encoding);
|
|
270
|
+
}
|
|
279
271
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
272
|
+
// Length of all chunks.
|
|
273
|
+
// this.writeUInt64LE(length);
|
|
274
|
+
// unknown seems to work better here - might revisit later.
|
|
275
|
+
this.writeBuffer(UNKNOWN_PLP_LEN);
|
|
276
|
+
|
|
277
|
+
// In the UNKNOWN_PLP_LEN case, the data is represented as a series of zero or more chunks.
|
|
278
|
+
if (length > 0) {
|
|
279
|
+
// One chunk.
|
|
280
|
+
this.writeUInt32LE(length);
|
|
281
|
+
if (Buffer.isBuffer(value)) {
|
|
282
|
+
this.writeBuffer(value);
|
|
283
|
+
} else {
|
|
284
|
+
this.makeRoomFor(length);
|
|
285
|
+
this.buffer.write(value, this.position, encoding);
|
|
286
|
+
this.position += length;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
284
289
|
|
|
285
|
-
|
|
286
|
-
|
|
290
|
+
// PLP_TERMINATOR (no more chunks).
|
|
291
|
+
return this.writeUInt32LE(0);
|
|
292
|
+
}
|
|
293
|
+
}, {
|
|
294
|
+
key: 'writeBuffer',
|
|
295
|
+
value: function writeBuffer(value) {
|
|
296
|
+
var length = value.length;
|
|
297
|
+
this.makeRoomFor(length);
|
|
298
|
+
value.copy(this.buffer, this.position);
|
|
299
|
+
return this.position += length;
|
|
300
|
+
}
|
|
301
|
+
}, {
|
|
302
|
+
key: 'writeMoney',
|
|
303
|
+
value: function writeMoney(value) {
|
|
304
|
+
this.writeInt32LE(Math.floor(value * SHIFT_RIGHT_32));
|
|
305
|
+
return this.writeInt32LE(value & -1);
|
|
306
|
+
}
|
|
307
|
+
}, {
|
|
308
|
+
key: 'data',
|
|
309
|
+
get: function get() {
|
|
310
|
+
this.newBuffer(0);
|
|
311
|
+
return this.compositeBuffer;
|
|
312
|
+
}
|
|
313
|
+
}]);
|
|
287
314
|
|
|
288
|
-
|
|
315
|
+
return WritableTrackingBuffer;
|
|
316
|
+
})();
|