stream_description.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. const parseServerType = require('../core/sdam/server_description').parseServerType;
  3. const RESPONSE_FIELDS = [
  4. 'minWireVersion',
  5. 'maxWireVersion',
  6. 'maxBsonObjectSize',
  7. 'maxMessageSizeBytes',
  8. 'maxWriteBatchSize',
  9. '__nodejs_mock_server__'
  10. ];
  11. class StreamDescription {
  12. constructor(address, options) {
  13. this.address = address;
  14. this.type = parseServerType(null);
  15. this.minWireVersion = undefined;
  16. this.maxWireVersion = undefined;
  17. this.maxBsonObjectSize = 16777216;
  18. this.maxMessageSizeBytes = 48000000;
  19. this.maxWriteBatchSize = 100000;
  20. this.compressors =
  21. options && options.compression && Array.isArray(options.compression.compressors)
  22. ? options.compression.compressors
  23. : [];
  24. }
  25. receiveResponse(response) {
  26. this.type = parseServerType(response);
  27. RESPONSE_FIELDS.forEach(field => {
  28. if (typeof response[field] !== 'undefined') {
  29. this[field] = response[field];
  30. }
  31. });
  32. if (response.compression) {
  33. this.compressor = this.compressors.filter(c => response.compression.indexOf(c) !== -1)[0];
  34. }
  35. }
  36. }
  37. module.exports = {
  38. StreamDescription
  39. };