(packets, callback)
| 440 | |
| 441 | var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text |
| 442 | var encodePayload = function encodePayload(packets, callback) { |
| 443 | // some packets may be added to the array while encoding, so the initial length must be saved |
| 444 | var length = packets.length; |
| 445 | var encodedPackets = new Array(length); |
| 446 | var count = 0; |
| 447 | packets.forEach(function (packet, i) { |
| 448 | // force base64 encoding for binary packets |
| 449 | encodePacket(packet, false, function (encodedPacket) { |
| 450 | encodedPackets[i] = encodedPacket; |
| 451 | if (++count === length) { |
| 452 | callback(encodedPackets.join(SEPARATOR)); |
| 453 | } |
| 454 | }); |
| 455 | }); |
| 456 | }; |
| 457 | var decodePayload = function decodePayload(encodedPayload, binaryType) { |
| 458 | var encodedPackets = encodedPayload.split(SEPARATOR); |
| 459 | var packets = []; |
no test coverage detected