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

Function decode

examples/basic-websocket-client/src/index.js:232–248  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

230}
231
232function decode(data) {
233 let i = 1; // skip "4" prefix
234
235 const packet = {
236 type: parseInt(data.charAt(i++), 10),
237 };
238
239 if (data.charAt(i)) {
240 packet.data = JSON.parse(data.substring(i));
241 }
242
243 if (!isPacketValid(packet)) {
244 throw new Error("invalid format");
245 }
246
247 return packet;
248}
249
250function isPacketValid(packet) {
251 switch (packet.type) {

Callers 1

#onMessageMethod · 0.70

Calls 1

isPacketValidFunction · 0.70

Tested by

no test coverage detected