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

Function encodePayload

packages/engine.io-parser/lib/index.ts:13–31  ·  view source on GitHub ↗
(
  packets: Packet[],
  callback: (encodedPayload: string) => void,
)

Source from the content-addressed store, hash-verified

11const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
12
13const encodePayload = (
14 packets: Packet[],
15 callback: (encodedPayload: string) => void,
16) => {
17 // some packets may be added to the array while encoding, so the initial length must be saved
18 const length = packets.length;
19 const encodedPackets = new Array(length);
20 let count = 0;
21
22 packets.forEach((packet, i) => {
23 // force base64 encoding for binary packets
24 encodePacket(packet, false, (encodedPacket) => {
25 encodedPackets[i] = encodedPacket;
26 if (++count === length) {
27 callback(encodedPackets.join(SEPARATOR));
28 }
29 });
30 });
31};
32
33const decodePayload = (
34 encodedPayload: string,

Callers 4

writeFunction · 0.90
index.tsFile · 0.50
browser.tsFile · 0.50
node.tsFile · 0.50

Calls 3

encodePacketFunction · 0.90
callbackFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected