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

Function decodeString

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

1248 */
1249
1250 function decodeString(str) {
1251 var p = {};
1252 var i = 0;
1253
1254 // look up type
1255 p.type = Number(str.charAt(0));
1256 if (null == exports.types[p.type]) return error();
1257
1258 // look up attachments if type binary
1259 if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
1260 var buf = '';
1261 while (str.charAt(++i) != '-') {
1262 buf += str.charAt(i);
1263 if (i == str.length) break;
1264 }
1265 if (buf != Number(buf) || str.charAt(i) != '-') {
1266 throw new Error('Illegal attachments');
1267 }
1268 p.attachments = Number(buf);
1269 }
1270
1271 // look up namespace (if any)
1272 if ('/' == str.charAt(i + 1)) {
1273 p.nsp = '';
1274 while (++i) {
1275 var c = str.charAt(i);
1276 if (',' == c) break;
1277 p.nsp += c;
1278 if (i == str.length) break;
1279 }
1280 } else {
1281 p.nsp = '/';
1282 }
1283
1284 // look up id
1285 var next = str.charAt(i + 1);
1286 if ('' !== next && Number(next) == next) {
1287 p.id = '';
1288 while (++i) {
1289 var c = str.charAt(i);
1290 if (null == c || Number(c) != c) {
1291 --i;
1292 break;
1293 }
1294 p.id += str.charAt(i);
1295 if (i == str.length) break;
1296 }
1297 p.id = Number(p.id);
1298 }
1299
1300 // look up json data
1301 if (str.charAt(++i)) {
1302 try {
1303 p.data = json.parse(str.substr(i));
1304 } catch(e){
1305 return error();
1306 }
1307 }

Callers 1

bundle.jsFile · 0.85

Calls 2

errorFunction · 0.85
debugFunction · 0.85

Tested by

no test coverage detected