* Encode packet as string.
(obj: Packet)
| 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 |
no test coverage detected