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

Function _deconstructPacket

packages/socket.io-parser/lib/binary.ts:20–43  ·  view source on GitHub ↗
(data, buffers)

Source from the content-addressed store, hash-verified

18}
19
20function _deconstructPacket(data, buffers) {
21 if (!data) return data;
22
23 if (isBinary(data)) {
24 const placeholder = { _placeholder: true, num: buffers.length };
25 buffers.push(data);
26 return placeholder;
27 } else if (Array.isArray(data)) {
28 const newData = new Array(data.length);
29 for (let i = 0; i < data.length; i++) {
30 newData[i] = _deconstructPacket(data[i], buffers);
31 }
32 return newData;
33 } else if (typeof data === "object" && !(data instanceof Date)) {
34 const newData = {};
35 for (const key in data) {
36 if (Object.prototype.hasOwnProperty.call(data, key)) {
37 newData[key] = _deconstructPacket(data[key], buffers);
38 }
39 }
40 return newData;
41 }
42 return data;
43}
44
45/**
46 * Reconstructs a binary packet from its placeholder packet and buffers

Callers 1

deconstructPacketFunction · 0.70

Calls 1

isBinaryFunction · 0.90

Tested by

no test coverage detected