encode method

dynamic encode(
  1. dynamic obj
)

Encode a packet as a single string if non-binary, or as a buffer sequence, depending on packet type.

@param {Object} obj - packet object @param {Function} callback - function to handle encodings (likely engine.write) @return Calls callback with Array of encodings @api public

Implementation

encode(obj) {
  if (_logger.isLoggable(Level.FINE)) {
    _logger.fine('encoding packet $obj');
  }

  if (EVENT == obj['type'] || ACK == obj['type']) {
    if (hasBinary(obj)) {
      obj['type'] = obj['type'] == EVENT ? BINARY_EVENT : BINARY_ACK;
      return encodeAsBinary(obj);
    }
  }
  return [encodeAsString(obj)];
}