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

Method encode

packages/socket.io-parser/lib/index.ts:63–80  ·  view source on GitHub ↗

* Encode a packet as a single string if non-binary, or as a * buffer sequence, depending on packet type. * * @param {Object} obj - packet object

(obj: Packet)

Source from the content-addressed store, hash-verified

61 * @param {Object} obj - packet object
62 */
63 public encode(obj: Packet) {
64 debug("encoding packet %j", obj);
65
66 if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
67 if (hasBinary(obj)) {
68 return this.encodeAsBinary({
69 type:
70 obj.type === PacketType.EVENT
71 ? PacketType.BINARY_EVENT
72 : PacketType.BINARY_ACK,
73 nsp: obj.nsp,
74 data: obj.data,
75 id: obj.id,
76 });
77 }
78 }
79 return [this.encodeAsString(obj)];
80 }
81
82 /**
83 * Encode packet as string.

Callers 1

testFunction · 0.95

Calls 4

encodeAsBinaryMethod · 0.95
encodeAsStringMethod · 0.95
hasBinaryFunction · 0.90
debugFunction · 0.85

Tested by 1

testFunction · 0.76