MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / encodeAsString

Function encodeAsString

sdk/src/CloudSocketClientLib.js:6559–6597  ·  view source on GitHub ↗

* Encode packet as string. * * @param {Object} packet * @return {String} encoded * @api private

(obj)

Source from the content-addressed store, hash-verified

6557 */
6558
6559 function encodeAsString(obj) {
6560 var str = '';
6561 var nsp = false;
6562
6563 // first is type
6564 str += obj.type;
6565
6566 // attachments if we have them
6567 if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
6568 str += obj.attachments;
6569 str += '-';
6570 }
6571
6572 // if we have a namespace other than `/`
6573 // we append it followed by a comma `,`
6574 if (obj.nsp && '/' != obj.nsp) {
6575 nsp = true;
6576 str += obj.nsp;
6577 }
6578
6579 // immediately followed by the id
6580 if (null != obj.id) {
6581 if (nsp) {
6582 str += ',';
6583 nsp = false;
6584 }
6585 str += obj.id;
6586 }
6587
6588 // json data
6589 if (null != obj.data) {
6590 if (nsp)
6591 str += ',';
6592 str += json.stringify(obj.data);
6593 }
6594
6595 debug('encoded %j as %s', obj, str);
6596 return str;
6597 }
6598
6599 /**
6600 * Encode packet as 'buffer sequence' by removing blobs, and

Callers 2

writeEncodingFunction · 0.70

Calls 1

debugFunction · 0.70

Tested by

no test coverage detected