How to use the ref-napi.alloc function in ref-napi

To help you get started, we’ve selected a few ref-napi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
function put1Internal() {

    if (isLocked(jsQueueManager._hConn)) {
      return setImmediate(put1Internal);
    } else {
      lock(jsQueueManager._hConn);
    }

    var mqRc = ref.alloc(MQT.LONG);
    var mqCc = ref.alloc(MQT.LONG);

    var mqMd = MQMD._copyMDtoC(jsmd);
    var mqOd = MQOD._copyODtoC(jsod);
    var mqPmo = MQPMO._copyPMOtoC(jspmo);

    // If it's a string, then we need to create a Buffer from it.
    // We also set the MQMD Format
    // TODO: Are there any string codepage conversions we should look at here?
    if (buf) {
      if (typeof buf == "string") {
        buf = Buffer.from(buf);
        u.setMQIString(mqMd.Format,"MQSTR");
      } else {
        checkParam(buf,Buffer,'Buffer');
      }
    }
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
function putInternal() {

    if (isLocked(jsObject._mqQueueManager._hConn)) {
      return setImmediate(putInternal);
    } else {
      lock(jsObject._mqQueueManager._hConn);
    }

    var mqRc = ref.alloc(MQT.LONG);
    var mqCc = ref.alloc(MQT.LONG);

    var mqMd = MQMD._copyMDtoC(jsmd);
    var mqPmo = MQPMO._copyPMOtoC(jspmo);

    // If it's a string, then we need to create a Buffer from it.
    // We also set the MQMD Format
    // TODO: Are there any string codepage conversions we should look at here?
    //       Do we need to set the CCSID in some way?
    if (buf) {
      if (typeof buf == "string") {
        buf = Buffer.from(buf);
        u.setMQIString(mqMd.Format,"MQSTR");
      } else {
        checkParam(buf,Buffer,'Buffer');
      }
    }
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
function openInternal () {
    // check if hConn is already being used
    if (isLocked(jsQueueManager._hConn)) {
      return setImmediate(openInternal);
    } else {
      lock(jsQueueManager._hConn);
    }

    var mqHObj  = ref.alloc(MQT.HOBJ);
    var mqRc = ref.alloc(MQT.LONG);
    var mqCc = ref.alloc(MQT.LONG);
    var mqOd = MQOD._copyODtoC(jsod);
    var err;

    if (useAsync) {
      libmqm.MQOPEN.async(jsQueueManager._hConn,mqOd.ref(),jsOpenOptions,mqHObj,mqCc,mqRc, function(error,resp) {
        unlock(jsQueueManager._hConn);

        MQOD._copyODfromC(mqOd,jsod);

        var jsHObj = mqHObj.deref();
        var jsRc = mqRc.deref();
        var jsCc = mqCc.deref();

        var jsObject = new MQObject(jsHObj,jsQueueManager,jsod.ObjectName);
        err = new MQError(jsCc,jsRc,"OPEN");
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
exports.Inq = function(jsObject,jsSelectors,cb) {
  checkParamCB(cb);
  checkParam(jsObject, MQObject, 'MQObject',true);
  checkArray(jsSelectors);

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var jsRc;
  var jsCc;
  var i;
  var charAttrLen = 0;
  var charLen;
  var badSelector = false;
  var selector;

  var mqSelectors = new mqLongArray(jsSelectors.length);
  for (i=0;i= MQC.MQIA_FIRST && selector <= MQC.MQIA_LAST) {
      // Do nothing.
    } else if (selector >= MQC.MQCA_FIRST && selector <= MQC.MQCA_LAST) {
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
exports.SetMp = function(jsQueueManager,jsHMsg,jssmpo,name,jspd,value,cb) {
  checkParamCB(cb);
  checkParam(jsQueueManager, MQQueueManager, 'MQQueueManager');
  checkParam(jssmpo, MQMPO.MQSMPO, 'MQSMPO');
  checkParam(jspd  , MQMPO.MQPD  , 'MQPD');
  checkParam(name, 'string', 'string');

  var mqHMsg  = jsHMsg;
  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var mqSmpo = MQMPO._copySMPOtoC(jssmpo);
  var mqPd   = MQMPO._copyPDtoC(jspd);

  var vsName = new MQT.CHARV();
  var ptr;
  var len;
  var type;

  u.defaultCharV(vsName);
  u.setMQICharV(vsName,name);

  // TODO: Handle all the possible MQTYPE values including FLOAT and
  //       different sized ints
  if (typeof value == 'string') {
    ptr =  Buffer.from(value,'utf8');
    len = value.length;
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
exports.Cmit = function(jsQueueManager, cb) {
  checkParamCB(cb);
  checkParam(jsQueueManager, MQQueueManager, 'MQQueueManager');

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);

  libmqm.MQCMIT(jsQueueManager._hConn,mqCc,mqRc);

  var jsRc = mqRc.deref();
  var jsCc = mqCc.deref();
  var err = new MQError(jsCc,jsRc,"CMIT");

  if (cb) {
    if (jsCc != MQC.MQCC_OK) {
      cb(err);
    } else {
      cb(null);
    }
  } else {
    if (jsCc != MQC.MQCC_OK) {
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
exports.GetSync = function(jsObject,jsmd,jsgmo,buf,cb) {
  checkParamCB(cb);
  checkParam(jsObject,MQObject, 'MQObject');
  checkParam(jsmd, MQMD.MQMD, 'MQMD');
  checkParam(jsgmo, MQGMO.MQGMO, 'MQGMO');
  checkParam(buf,Buffer,'Buffer');

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var datalen = ref.alloc(MQT.LONG);

  var mqMd = MQMD._copyMDtoC(jsmd);
  var mqGmo = MQGMO._copyGMOtoC(jsgmo);

  var bufflen = 0;
  var ptr = ref.NULL_POINTER;
  if (buf) {
    bufflen = buf.length;
  }

  if (bufflen > 0) {
    ptr = buf;
  }
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
exports.Stat  = function(jsQueueManager, jsType, cb) {
  checkParamCB(cb);
  checkParam(jsQueueManager, MQQueueManager, 'MQQueueManager');
  checkParam(jsType,'number','number');

  var jsRc = MQC.MQCC_OK;
  var jsCc = MQC.MQRC_NONE;

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var jssts = new MQSTS.MQSTS();

  var mqsts = MQSTS._copySTStoC(jssts);

  libmqm.MQSTAT(jsQueueManager._hConn,jsType,mqsts.ref(), mqCc,mqRc);

  jsRc = mqRc.deref();
  jsCc = mqCc.deref();
  if (jsCc == MQC.MQCC_OK) {
    MQSTS._copySTSfromC(mqsts,jssts);
  }

  var err = new MQError(jsCc,jsRc,"STAT");

  if (cb) {
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
function sub(jsQueueManager,jsQueueObject,jssd,useAsync,cb)  {
  checkParam(jsQueueManager, MQQueueManager, 'MQQueueManager');
  checkParamRequired(jsQueueObject, MQObject,'MQObject',false);
  checkParam(jssd, MQSD.MQSD, 'MQSD');

  var jsHObjQ = MQC.MQHO_UNUSABLE_HOBJ;
  if (jsQueueObject) {
    jsHObjQ = jsQueueObject._jshObj;
  }

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var mqHObjQ  = ref.alloc(MQT.HOBJ, jsHObjQ);
  var mqHObjSub = ref.alloc(MQT.HOBJ);

  subInternal();
  function subInternal() {

    if (isLocked(jsQueueManager._hConn)) {
      return setImmediate(subInternal);
    } else {
      lock(jsQueueManager._hConn);
    }
    var mqSd = MQSD._copySDtoC(jssd);
    if (useAsync) {
      libmqm.MQSUB.async(jsQueueManager._hConn,
                   mqSd.ref(),
                   mqHObjQ,
                   mqHObjSub,
github ibm-messaging / mq-mqi-nodejs / lib / mqi.js View on Github external
function sub(jsQueueManager,jsQueueObject,jssd,useAsync,cb)  {
  checkParam(jsQueueManager, MQQueueManager, 'MQQueueManager');
  checkParamRequired(jsQueueObject, MQObject,'MQObject',false);
  checkParam(jssd, MQSD.MQSD, 'MQSD');

  var jsHObjQ = MQC.MQHO_UNUSABLE_HOBJ;
  if (jsQueueObject) {
    jsHObjQ = jsQueueObject._jshObj;
  }

  var mqRc = ref.alloc(MQT.LONG);
  var mqCc = ref.alloc(MQT.LONG);
  var mqHObjQ  = ref.alloc(MQT.HOBJ, jsHObjQ);
  var mqHObjSub = ref.alloc(MQT.HOBJ);

  subInternal();
  function subInternal() {

    if (isLocked(jsQueueManager._hConn)) {
      return setImmediate(subInternal);
    } else {
      lock(jsQueueManager._hConn);
    }
    var mqSd = MQSD._copySDtoC(jssd);
    if (useAsync) {
      libmqm.MQSUB.async(jsQueueManager._hConn,
                   mqSd.ref(),
                   mqHObjQ,
                   mqHObjSub,
                   mqCc,