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

Method encodeAsString

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

* Encode packet as string.

(obj: Packet)

Source from the content-addressed store, hash-verified

84 */
85
86 private encodeAsString(obj: Packet) {
87 // first is type
88 let str = "" + obj.type;
89
90 // attachments if we have them
91 if (
92 obj.type === PacketType.BINARY_EVENT ||
93 obj.type === PacketType.BINARY_ACK
94 ) {
95 str += obj.attachments + "-";
96 }
97
98 // if we have a namespace other than `/`
99 // we append it followed by a comma `,`
100 if (obj.nsp && "/" !== obj.nsp) {
101 str += obj.nsp + ",";
102 }
103
104 // immediately followed by the id
105 if (null != obj.id) {
106 str += obj.id;
107 }
108
109 // json data
110 if (null != obj.data) {
111 str += JSON.stringify(obj.data, this.replacer);
112 }
113
114 debug("encoded %j as %s", obj, str);
115 return str;
116 }
117
118 /**
119 * Encode packet as 'buffer sequence' by removing blobs, and

Callers 2

encodeMethod · 0.95
encodeAsBinaryMethod · 0.95

Calls 1

debugFunction · 0.85

Tested by

no test coverage detected