MCPcopy Create free account
hub / github.com/ReactJSResources/react-webpack-babel / encodeAsString

Function encodeAsString

public/bundle.js:1123–1160  ·  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

1121 */
1122
1123 function encodeAsString(obj) {
1124 var str = '';
1125 var nsp = false;
1126
1127 // first is type
1128 str += obj.type;
1129
1130 // attachments if we have them
1131 if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
1132 str += obj.attachments;
1133 str += '-';
1134 }
1135
1136 // if we have a namespace other than `/`
1137 // we append it followed by a comma `,`
1138 if (obj.nsp && '/' != obj.nsp) {
1139 nsp = true;
1140 str += obj.nsp;
1141 }
1142
1143 // immediately followed by the id
1144 if (null != obj.id) {
1145 if (nsp) {
1146 str += ',';
1147 nsp = false;
1148 }
1149 str += obj.id;
1150 }
1151
1152 // json data
1153 if (null != obj.data) {
1154 if (nsp) str += ',';
1155 str += json.stringify(obj.data);
1156 }
1157
1158 debug('encoded %j as %s', obj, str);
1159 return str;
1160 }
1161
1162 /**
1163 * Encode packet as 'buffer sequence' by removing blobs, and

Callers 2

bundle.jsFile · 0.85
writeEncodingFunction · 0.85

Calls 1

debugFunction · 0.85

Tested by

no test coverage detected