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

Function encodePacketToBinary

packages/engine.io-parser/lib/encodePacket.ts:32–46  ·  view source on GitHub ↗
(
  packet: Packet,
  callback: (encodedPacket: RawData) => void,
)

Source from the content-addressed store, hash-verified

30let TEXT_ENCODER;
31
32export function encodePacketToBinary(
33 packet: Packet,
34 callback: (encodedPacket: RawData) => void,
35) {
36 if (packet.data instanceof ArrayBuffer || ArrayBuffer.isView(packet.data)) {
37 return callback(toBuffer(packet.data, false));
38 }
39 encodePacket(packet, true, (encoded) => {
40 if (!TEXT_ENCODER) {
41 // lazily created for compatibility with Node.js 10
42 TEXT_ENCODER = new TextEncoder();
43 }
44 callback(TEXT_ENCODER.encode(encoded));
45 });
46}

Callers

nothing calls this directly

Calls 4

toBufferFunction · 0.85
encodePacketFunction · 0.70
encodeMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected