exports.send = function()

in lib/post-iot.js [77:102]


exports.send = function(service, target, records, callback) {
  switch(target.collapse) {
    case "JSON": {
      // We have multiple messages, collapse them in a single JSON Array
      var entries = { Records: records.map(function(record) { return JSON.parse(record.data.toString()); }) };
      service.publish({ topic: target.destination, payload: JSON.stringify(entries), qos: 0 }, callback);
      break;
    }
    case "concat-b64": {
      // We have multiple messages, collapse them in a single buffer
      var data = Buffer.concat([].concat.apply([], records.map(function(record) { return record.data; })));
      service.publish({ topic: target.destination, payload: data.toString('base64'), qos: 0 }, callback);
      break;
    }
    case "concat": {
      // We have multiple messages, collapse them in a single buffer
      var data = Buffer.concat([].concat.apply([], records.map(function(record) { return record.data; })));
      service.publish({ topic: target.destination, payload: data, qos: 0 }, callback);
      break;
    }
    default: {
      // We have a single message, let's send it
      service.publish({ topic: target.destination, payload: records[0].data, qos: 0 }, callback);
    }
  }
};