(packet)
| 220 | } |
| 221 | |
| 222 | function encode(packet) { |
| 223 | let output = "" + packet.type; |
| 224 | |
| 225 | if (packet.data) { |
| 226 | output += JSON.stringify(packet.data); |
| 227 | } |
| 228 | |
| 229 | return output; |
| 230 | } |
| 231 | |
| 232 | function decode(data) { |
| 233 | let i = 1; // skip "4" prefix |