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

Function encodePacket

packages/engine.io-parser/lib/encodePacket.ts:3–15  ·  view source on GitHub ↗
(
  { type, data }: Packet,
  supportsBinary: boolean,
  callback: (encodedPacket: RawData) => void,
)

Source from the content-addressed store, hash-verified

1import { PACKET_TYPES, Packet, RawData } from "./commons.js";
2
3export const encodePacket = (
4 { type, data }: Packet,
5 supportsBinary: boolean,
6 callback: (encodedPacket: RawData) => void,
7) => {
8 if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
9 return callback(
10 supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"),
11 );
12 }
13 // plain string
14 return callback(PACKET_TYPES[type] + (data || ""));
15};
16
17const toBuffer = (data: BufferSource, forceBufferConversion: boolean) => {
18 if (

Callers 5

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

Calls 2

toBufferFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected