MCPcopy Index your code
hub / github.com/PrairieLearn/PrairieLearn / encodeAsString

Function encodeAsString

public/javascripts/socket.io.js:1176–1213  ·  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

1174 */
1175
1176 function encodeAsString(obj) {
1177 var str = '';
1178 var nsp = false;
1179
1180 // first is type
1181 str += obj.type;
1182
1183 // attachments if we have them
1184 if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
1185 str += obj.attachments;
1186 str += '-';
1187 }
1188
1189 // if we have a namespace other than `/`
1190 // we append it followed by a comma `,`
1191 if (obj.nsp && '/' != obj.nsp) {
1192 nsp = true;
1193 str += obj.nsp;
1194 }
1195
1196 // immediately followed by the id
1197 if (null != obj.id) {
1198 if (nsp) {
1199 str += ',';
1200 nsp = false;
1201 }
1202 str += obj.id;
1203 }
1204
1205 // json data
1206 if (null != obj.data) {
1207 if (nsp) str += ',';
1208 str += json.stringify(obj.data);
1209 }
1210
1211 debug('encoded %j as %s', obj, str);
1212 return str;
1213 }
1214
1215 /**
1216 * Encode packet as 'buffer sequence' by removing blobs, and

Callers 2

socket.io.jsFile · 0.85
writeEncodingFunction · 0.85

Calls 1

debugFunction · 0.85

Tested by

no test coverage detected