code: function encodeAsString(obj) {
      // first is type
      var str = "" + obj.type;
  
      // attachments if we have them
      if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
        str += obj.attachments + "-";
      }
  
      // if we have a namespace other than `/`
      // we append it followed by a comma `,`
      if (obj.nsp && "/" !== obj.nsp) {
        str += obj.nsp + ",";
      }
  
      // immediately followed by the id
      if (null != obj.id) {
        str += obj.id;
      }
  
      // json data
      if (null != obj.data) {
        var payload = tryStringify(obj.data);
        if (payload !== false) {
          str += payload;
        } else {
          return ERROR_PACKET;
        }
      }
  
      debug("encoded %j as %s", obj, str);
      return str;
    }
docs: Encode packet as string.
  
  @param {Object} packet
  @return {String} encoded
  @api private