1 var DATA_TYPES = require('../../constants/DataTypes'),
  2   Helpers = require('../../utils/Helpers'),
  3   ErrorMessages = require('../../constants/ErrorMessages'),
  4   CAS = require('../../constants/CASConstants');
  5 
  6 module.exports = OpenDatabasePacket;
  7 
  8 /**
  9  * Constructor
 10  * @param options
 11  * @constructor
 12  */
 13 function OpenDatabasePacket(options) {
 14   options = options || {};
 15 
 16   this.database = options.database;
 17   this.user = options.user;
 18   this.password = options.password;
 19   this.casInfo = options.casInfo;
 20 
 21   this.responseCode = 0;
 22   this.errorCode = 0;
 23   this.errorMsg = '';
 24 }
 25 
 26 /**
 27  * Write data
 28  * @param writer
 29  */
 30 OpenDatabasePacket.prototype.write = function (writer) {
 31   writer._writeFixedLengthString(this.database, 0, 32);
 32   writer._writeFixedLengthString(this.user, 0, 32);
 33   writer._writeFixedLengthString(this.password, 0, 32);
 34   writer._writeFiller(512, 0);
 35   writer._writeFiller(20, 0);
 36 
 37   return writer;
 38 };
 39 
 40 /**
 41  * Read data
 42  * @param parser
 43  */
 44 OpenDatabasePacket.prototype.parse = function (parser) {
 45   var reponseLength = parser._parseInt();
 46   this.casInfo = parser._parseBytes(DATA_TYPES.CAS_INFO_SIZE);
 47 
 48   this.responseCode = parser._parseInt();
 49   if (this.responseCode < 0) {
 50     this.errorCode = parser._parseInt();
 51     this.errorMsg = parser._parseNullTerminatedString(reponseLength - DATA_TYPES.INT_SIZEOF * 2);
 52     if (this.errorMsg.length == 0) {
 53       this.errorMsg = Helpers._resolveErrorCode(this.errorCode);
 54     }
 55   } else {
 56     //this.processId = this.responseCode;
 57     this.brokerInfo = parser._parseBytes(DATA_TYPES.BROKERINFO_SIZEOF);
 58     this.sessionId = parser._parseInt();
 59   }
 60 
 61   return this;
 62 };
 63 
 64 
 65