(packets, callback)
| 353 | |
| 354 | var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text |
| 355 | var encodePayload = function encodePayload(packets, callback) { |
| 356 | // some packets may be added to the array while encoding, so the initial length must be saved |
| 357 | var length = packets.length; |
| 358 | var encodedPackets = new Array(length); |
| 359 | var count = 0; |
| 360 | packets.forEach(function (packet, i) { |
| 361 | // force base64 encoding for binary packets |
| 362 | encodePacket(packet, false, function (encodedPacket) { |
| 363 | encodedPackets[i] = encodedPacket; |
| 364 | if (++count === length) { |
| 365 | callback(encodedPackets.join(SEPARATOR)); |
| 366 | } |
| 367 | }); |
| 368 | }); |
| 369 | }; |
| 370 | var decodePayload = function decodePayload(encodedPayload, binaryType) { |
| 371 | var encodedPackets = encodedPayload.split(SEPARATOR); |
| 372 | var packets = []; |
no test coverage detected