encodeAsString static method

String encodeAsString(
  1. dynamic obj
)

Encode packet as string.

@param {Object} packet @return {String} encoded @api private

Implementation

static String encodeAsString(obj) {
  // first is type
  var str = '${obj['type']}';

  // attachments if we have them
  if (BINARY_EVENT == obj['type'] || BINARY_ACK == obj['type']) {
    str += '${obj['attachments']}-';
  }

  // if we have a namespace other than `/`
  // we append it followed by a comma `,`
  if (obj['nsp'] != null && '/' != obj['nsp']) {
    str += obj['nsp'] + ',';
  }

  // immediately followed by the id
  if (null != obj['id']) {
    str += '${obj['id']}';
  }

  // json data
  if (null != obj['data']) {
    str += json.encode(obj['data']);
  }

  _logger.fine('encoded $obj as $str');
  return str;
}