@@ -5,7 +5,7 @@ import { ReadPreference } from '../read_preference';
5
5
import type { ClientSession } from '../sessions' ;
6
6
import { databaseNamespace } from '../utils' ;
7
7
import type { CommandOptions } from './connection' ;
8
- import { OP_GETMORE , OP_KILL_CURSORS , OP_MSG , OP_QUERY } from './wire_protocol/constants' ;
8
+ import { OP_MSG , OP_QUERY } from './wire_protocol/constants' ;
9
9
10
10
// Incrementing request id
11
11
let _requestId = 0 ;
@@ -26,7 +26,7 @@ const SHARD_CONFIG_STALE = 4;
26
26
const AWAIT_CAPABLE = 8 ;
27
27
28
28
/** @internal */
29
- export type WriteProtocolMessageType = Query | Msg | GetMore | KillCursor ;
29
+ export type WriteProtocolMessageType = Query | Msg ;
30
30
31
31
/** @internal */
32
32
export interface OpQueryOptions extends CommandOptions {
@@ -270,194 +270,6 @@ export class Query {
270
270
}
271
271
}
272
272
273
- /** @internal */
274
- export interface OpGetMoreOptions {
275
- numberToReturn ?: number ;
276
- }
277
-
278
- /**************************************************************
279
- * GETMORE
280
- **************************************************************/
281
- /** @internal */
282
- export class GetMore {
283
- numberToReturn : number ;
284
- requestId : number ;
285
- ns : string ;
286
- cursorId : Long ;
287
-
288
- constructor ( ns : string , cursorId : Long , opts : OpGetMoreOptions = { } ) {
289
- this . numberToReturn = opts . numberToReturn || 0 ;
290
- this . requestId = _requestId ++ ;
291
- this . ns = ns ;
292
- this . cursorId = cursorId ;
293
- }
294
-
295
- // Uses a single allocated buffer for the process, avoiding multiple memory allocations
296
- toBin ( ) : Buffer [ ] {
297
- const length = 4 + Buffer . byteLength ( this . ns ) + 1 + 4 + 8 + 4 * 4 ;
298
- // Create command buffer
299
- let index = 0 ;
300
- // Allocate buffer
301
- const _buffer = Buffer . alloc ( length ) ;
302
-
303
- // Write header information
304
- // index = write32bit(index, _buffer, length);
305
- _buffer [ index + 3 ] = ( length >> 24 ) & 0xff ;
306
- _buffer [ index + 2 ] = ( length >> 16 ) & 0xff ;
307
- _buffer [ index + 1 ] = ( length >> 8 ) & 0xff ;
308
- _buffer [ index ] = length & 0xff ;
309
- index = index + 4 ;
310
-
311
- // index = write32bit(index, _buffer, requestId);
312
- _buffer [ index + 3 ] = ( this . requestId >> 24 ) & 0xff ;
313
- _buffer [ index + 2 ] = ( this . requestId >> 16 ) & 0xff ;
314
- _buffer [ index + 1 ] = ( this . requestId >> 8 ) & 0xff ;
315
- _buffer [ index ] = this . requestId & 0xff ;
316
- index = index + 4 ;
317
-
318
- // index = write32bit(index, _buffer, 0);
319
- _buffer [ index + 3 ] = ( 0 >> 24 ) & 0xff ;
320
- _buffer [ index + 2 ] = ( 0 >> 16 ) & 0xff ;
321
- _buffer [ index + 1 ] = ( 0 >> 8 ) & 0xff ;
322
- _buffer [ index ] = 0 & 0xff ;
323
- index = index + 4 ;
324
-
325
- // index = write32bit(index, _buffer, OP_GETMORE);
326
- _buffer [ index + 3 ] = ( OP_GETMORE >> 24 ) & 0xff ;
327
- _buffer [ index + 2 ] = ( OP_GETMORE >> 16 ) & 0xff ;
328
- _buffer [ index + 1 ] = ( OP_GETMORE >> 8 ) & 0xff ;
329
- _buffer [ index ] = OP_GETMORE & 0xff ;
330
- index = index + 4 ;
331
-
332
- // index = write32bit(index, _buffer, 0);
333
- _buffer [ index + 3 ] = ( 0 >> 24 ) & 0xff ;
334
- _buffer [ index + 2 ] = ( 0 >> 16 ) & 0xff ;
335
- _buffer [ index + 1 ] = ( 0 >> 8 ) & 0xff ;
336
- _buffer [ index ] = 0 & 0xff ;
337
- index = index + 4 ;
338
-
339
- // Write collection name
340
- index = index + _buffer . write ( this . ns , index , 'utf8' ) + 1 ;
341
- _buffer [ index - 1 ] = 0 ;
342
-
343
- // Write batch size
344
- // index = write32bit(index, _buffer, numberToReturn);
345
- _buffer [ index + 3 ] = ( this . numberToReturn >> 24 ) & 0xff ;
346
- _buffer [ index + 2 ] = ( this . numberToReturn >> 16 ) & 0xff ;
347
- _buffer [ index + 1 ] = ( this . numberToReturn >> 8 ) & 0xff ;
348
- _buffer [ index ] = this . numberToReturn & 0xff ;
349
- index = index + 4 ;
350
-
351
- // Write cursor id
352
- // index = write32bit(index, _buffer, cursorId.getLowBits());
353
- _buffer [ index + 3 ] = ( this . cursorId . getLowBits ( ) >> 24 ) & 0xff ;
354
- _buffer [ index + 2 ] = ( this . cursorId . getLowBits ( ) >> 16 ) & 0xff ;
355
- _buffer [ index + 1 ] = ( this . cursorId . getLowBits ( ) >> 8 ) & 0xff ;
356
- _buffer [ index ] = this . cursorId . getLowBits ( ) & 0xff ;
357
- index = index + 4 ;
358
-
359
- // index = write32bit(index, _buffer, cursorId.getHighBits());
360
- _buffer [ index + 3 ] = ( this . cursorId . getHighBits ( ) >> 24 ) & 0xff ;
361
- _buffer [ index + 2 ] = ( this . cursorId . getHighBits ( ) >> 16 ) & 0xff ;
362
- _buffer [ index + 1 ] = ( this . cursorId . getHighBits ( ) >> 8 ) & 0xff ;
363
- _buffer [ index ] = this . cursorId . getHighBits ( ) & 0xff ;
364
- index = index + 4 ;
365
-
366
- // Return buffer
367
- return [ _buffer ] ;
368
- }
369
- }
370
-
371
- /**************************************************************
372
- * KILLCURSOR
373
- **************************************************************/
374
- /** @internal */
375
- export class KillCursor {
376
- ns : string ;
377
- requestId : number ;
378
- cursorIds : Long [ ] ;
379
-
380
- constructor ( ns : string , cursorIds : Long [ ] ) {
381
- this . ns = ns ;
382
- this . requestId = _requestId ++ ;
383
- this . cursorIds = cursorIds ;
384
- }
385
-
386
- // Uses a single allocated buffer for the process, avoiding multiple memory allocations
387
- toBin ( ) : Buffer [ ] {
388
- const length = 4 + 4 + 4 * 4 + this . cursorIds . length * 8 ;
389
-
390
- // Create command buffer
391
- let index = 0 ;
392
- const _buffer = Buffer . alloc ( length ) ;
393
-
394
- // Write header information
395
- // index = write32bit(index, _buffer, length);
396
- _buffer [ index + 3 ] = ( length >> 24 ) & 0xff ;
397
- _buffer [ index + 2 ] = ( length >> 16 ) & 0xff ;
398
- _buffer [ index + 1 ] = ( length >> 8 ) & 0xff ;
399
- _buffer [ index ] = length & 0xff ;
400
- index = index + 4 ;
401
-
402
- // index = write32bit(index, _buffer, requestId);
403
- _buffer [ index + 3 ] = ( this . requestId >> 24 ) & 0xff ;
404
- _buffer [ index + 2 ] = ( this . requestId >> 16 ) & 0xff ;
405
- _buffer [ index + 1 ] = ( this . requestId >> 8 ) & 0xff ;
406
- _buffer [ index ] = this . requestId & 0xff ;
407
- index = index + 4 ;
408
-
409
- // index = write32bit(index, _buffer, 0);
410
- _buffer [ index + 3 ] = ( 0 >> 24 ) & 0xff ;
411
- _buffer [ index + 2 ] = ( 0 >> 16 ) & 0xff ;
412
- _buffer [ index + 1 ] = ( 0 >> 8 ) & 0xff ;
413
- _buffer [ index ] = 0 & 0xff ;
414
- index = index + 4 ;
415
-
416
- // index = write32bit(index, _buffer, OP_KILL_CURSORS);
417
- _buffer [ index + 3 ] = ( OP_KILL_CURSORS >> 24 ) & 0xff ;
418
- _buffer [ index + 2 ] = ( OP_KILL_CURSORS >> 16 ) & 0xff ;
419
- _buffer [ index + 1 ] = ( OP_KILL_CURSORS >> 8 ) & 0xff ;
420
- _buffer [ index ] = OP_KILL_CURSORS & 0xff ;
421
- index = index + 4 ;
422
-
423
- // index = write32bit(index, _buffer, 0);
424
- _buffer [ index + 3 ] = ( 0 >> 24 ) & 0xff ;
425
- _buffer [ index + 2 ] = ( 0 >> 16 ) & 0xff ;
426
- _buffer [ index + 1 ] = ( 0 >> 8 ) & 0xff ;
427
- _buffer [ index ] = 0 & 0xff ;
428
- index = index + 4 ;
429
-
430
- // Write batch size
431
- // index = write32bit(index, _buffer, this.cursorIds.length);
432
- _buffer [ index + 3 ] = ( this . cursorIds . length >> 24 ) & 0xff ;
433
- _buffer [ index + 2 ] = ( this . cursorIds . length >> 16 ) & 0xff ;
434
- _buffer [ index + 1 ] = ( this . cursorIds . length >> 8 ) & 0xff ;
435
- _buffer [ index ] = this . cursorIds . length & 0xff ;
436
- index = index + 4 ;
437
-
438
- // Write all the cursor ids into the array
439
- for ( let i = 0 ; i < this . cursorIds . length ; i ++ ) {
440
- // Write cursor id
441
- // index = write32bit(index, _buffer, cursorIds[i].getLowBits());
442
- _buffer [ index + 3 ] = ( this . cursorIds [ i ] . getLowBits ( ) >> 24 ) & 0xff ;
443
- _buffer [ index + 2 ] = ( this . cursorIds [ i ] . getLowBits ( ) >> 16 ) & 0xff ;
444
- _buffer [ index + 1 ] = ( this . cursorIds [ i ] . getLowBits ( ) >> 8 ) & 0xff ;
445
- _buffer [ index ] = this . cursorIds [ i ] . getLowBits ( ) & 0xff ;
446
- index = index + 4 ;
447
-
448
- // index = write32bit(index, _buffer, cursorIds[i].getHighBits());
449
- _buffer [ index + 3 ] = ( this . cursorIds [ i ] . getHighBits ( ) >> 24 ) & 0xff ;
450
- _buffer [ index + 2 ] = ( this . cursorIds [ i ] . getHighBits ( ) >> 16 ) & 0xff ;
451
- _buffer [ index + 1 ] = ( this . cursorIds [ i ] . getHighBits ( ) >> 8 ) & 0xff ;
452
- _buffer [ index ] = this . cursorIds [ i ] . getHighBits ( ) & 0xff ;
453
- index = index + 4 ;
454
- }
455
-
456
- // Return buffer
457
- return [ _buffer ] ;
458
- }
459
- }
460
-
461
273
/** @internal */
462
274
export interface MessageHeader {
463
275
length : number ;
0 commit comments