MCPcopy
hub / github.com/socketio/socket.io / encodePayload

Function encodePayload

packages/engine.io/lib/parser-v3/index.ts:222–245  ·  view source on GitHub ↗
(packets, supportsBinary, callback)

Source from the content-addressed store, hash-verified

220 */
221
222export function encodePayload (packets, supportsBinary, callback) {
223 if (typeof supportsBinary === 'function') {
224 callback = supportsBinary;
225 supportsBinary = null;
226 }
227
228 if (supportsBinary && hasBinary(packets)) {
229 return encodePayloadAsBinary(packets, callback);
230 }
231
232 if (!packets.length) {
233 return callback('0:');
234 }
235
236 function encodeOne(packet, doneCallback) {
237 encodePacket(packet, supportsBinary, false, function(message) {
238 doneCallback(null, setLengthHeader(message));
239 });
240 }
241
242 map(packets, encodeOne, function(err, results) {
243 return callback(results.join(''));
244 });
245};
246
247function setLengthHeader(message) {
248 return message.length + ':' + message;

Callers

nothing calls this directly

Calls 5

encodePayloadAsBinaryFunction · 0.85
mapFunction · 0.85
hasBinaryFunction · 0.70
callbackFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected