(data, buffers)
| 18 | } |
| 19 | |
| 20 | function _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 |
no test coverage detected