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 = GetEngineVersionPacket;
  7 
  8 /**
  9  * Constructor
 10  * @param options
 11  * @constructor
 12  */
 13 function GetEngineVersionPacket(options) {
 14   options = options || {};
 15 
 16   this.casInfo = options.casInfo;
 17 
 18   this.engineVersion = '';
 19 
 20   this.responseCode = 0;
 21   this.errorCode = 0;
 22   this.errorMsg = '';
 23 }
 24 
 25 /**
 26  * Write data
 27  * @param writer
 28  */
 29 GetEngineVersionPacket.prototype.write = function (writer) {
 30   var bufferLength = DATA_TYPES.DATA_LENGTH_SIZEOF + DATA_TYPES.CAS_INFO_SIZE +
 31     DATA_TYPES.BYTE_SIZEOF + DATA_TYPES.INT_SIZEOF + DATA_TYPES.BYTE_SIZEOF;
 32 
 33   writer._writeInt(bufferLength - DATA_TYPES.DATA_LENGTH_SIZEOF - DATA_TYPES.CAS_INFO_SIZE);
 34   writer._writeBytes(DATA_TYPES.CAS_INFO_SIZE, this.casInfo);
 35   writer._writeByte(CAS.CASFunctionCode.CAS_FC_GET_DB_VERSION);
 36   writer._writeInt(DATA_TYPES.BYTE_SIZEOF);
 37   writer._writeByte(1);
 38 
 39   return writer;
 40 };
 41 
 42 /**
 43  * Read data
 44  * @param parser
 45  */
 46 GetEngineVersionPacket.prototype.parse = function (parser) {
 47   var reponseLength = parser._parseInt();
 48   this.casInfo = parser._parseBytes(DATA_TYPES.CAS_INFO_SIZE);
 49   this.responseCode = parser._parseInt();
 50   if (this.responseCode < 0) {
 51     this.errorCode = parser._parseInt();
 52     this.errorMsg = parser._parseNullTerminatedString(reponseLength - 2 * DATA_TYPES.INT_SIZEOF);
 53     if (this.errorMsg.length == 0) {
 54       this.errorMsg = Helpers._resolveErrorCode(this.errorCode);
 55     }
 56   } else {
 57     this.engineVersion = parser._parseNullTerminatedString(reponseLength - DATA_TYPES.INT_SIZEOF);
 58   }
 59 
 60   return this;
 61 };
 62 
 63 
 64