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

Function decodeString

public/javascripts/socket.io.js:1303–1360  ·  view source on GitHub ↗

* Decode a packet String (JSON data) * * @param {String} str * @return {Object} packet * @api private

(str)

Source from the content-addressed store, hash-verified

1301 */
1302
1303 function decodeString(str) {
1304 var p = {};
1305 var i = 0;
1306
1307 // look up type
1308 p.type = Number(str.charAt(0));
1309 if (null == exports.types[p.type]) return error();
1310
1311 // look up attachments if type binary
1312 if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
1313 var buf = '';
1314 while (str.charAt(++i) != '-') {
1315 buf += str.charAt(i);
1316 if (i == str.length) break;
1317 }
1318 if (buf != Number(buf) || str.charAt(i) != '-') {
1319 throw new Error('Illegal attachments');
1320 }
1321 p.attachments = Number(buf);
1322 }
1323
1324 // look up namespace (if any)
1325 if ('/' == str.charAt(i + 1)) {
1326 p.nsp = '';
1327 while (++i) {
1328 var c = str.charAt(i);
1329 if (',' == c) break;
1330 p.nsp += c;
1331 if (i == str.length) break;
1332 }
1333 } else {
1334 p.nsp = '/';
1335 }
1336
1337 // look up id
1338 var next = str.charAt(i + 1);
1339 if ('' !== next && Number(next) == next) {
1340 p.id = '';
1341 while (++i) {
1342 var c = str.charAt(i);
1343 if (null == c || Number(c) != c) {
1344 --i;
1345 break;
1346 }
1347 p.id += str.charAt(i);
1348 if (i == str.length) break;
1349 }
1350 p.id = Number(p.id);
1351 }
1352
1353 // look up json data
1354 if (str.charAt(++i)) {
1355 p = tryParse(p, str.substr(i));
1356 }
1357
1358 debug('decoded %s as %j', str, p);
1359 return p;
1360 }

Callers 1

socket.io.jsFile · 0.85

Calls 3

tryParseFunction · 0.85
debugFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected