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

Function decodePacket

packages/engine.io-parser/lib/decodePacket.ts:9–38  ·  view source on GitHub ↗
(
  encodedPacket: RawData,
  binaryType?: BinaryType,
)

Source from the content-addressed store, hash-verified

7} from "./commons.js";
8
9export const decodePacket = (
10 encodedPacket: RawData,
11 binaryType?: BinaryType,
12): Packet => {
13 if (typeof encodedPacket !== "string") {
14 return {
15 type: "message",
16 data: mapBinary(encodedPacket, binaryType),
17 };
18 }
19 const type = encodedPacket.charAt(0);
20 if (type === "b") {
21 const buffer = Buffer.from(encodedPacket.substring(1), "base64");
22 return {
23 type: "message",
24 data: mapBinary(buffer, binaryType),
25 };
26 }
27 if (!PACKET_TYPES_REVERSE[type]) {
28 return ERROR_PACKET;
29 }
30 return encodedPacket.length > 1
31 ? {
32 type: PACKET_TYPES_REVERSE[type],
33 data: encodedPacket.substring(1),
34 }
35 : {
36 type: PACKET_TYPES_REVERSE[type],
37 };
38};
39
40const mapBinary = (data: RawData, binaryType?: BinaryType) => {
41 switch (binaryType) {

Callers 4

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

Calls 1

mapBinaryFunction · 0.70

Tested by

no test coverage detected