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