Generates message from the provided data object
with respect for the message type

@private
@this    Fbbot#
@param   {string} type - message type
@param   {object} data - message data object
@returns {object} - generated message object
180279
function generateMessage(type, data)
{
  var message;

  switch (type)
  {
    // default message type, no need to perform special actions, will be sent as is
    case types.MESSAGE:
      message = data;
      break;

    case types.TEXT:
      // `text` must be UTF-8 and has a 320 character limit
      // https://developers.facebook.com/docs/messenger-platform/send-api-reference/text-message
      message = {text: data.substr(0, 320)};
      break;

    case types.AUDIO:
    case types.FILE:
    case types.IMAGE:
    case types.VIDEO:
      message = {attachment: {type: type, payload: {url: data}}};
      break;

    case types.QUICK_REPLIES:
      // `quick_replies` is limited to 10
      // https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-replies
      message = {text: data.text, quick_replies: data.quick_replies.slice(0, 10)};
      break;

    case types.GENERIC:
      message = templates.generic.call(this, data);
      break;

    case types.BUTTON:
      message = templates.button.call(this, data);
      break;

    case types.RECEIPT:
      message = templates.receipt.call(this, data);
      break;

    default:
      this.logger.error({message: 'Unrecognized message type', type: type, payload: data});
  }

  return message;
}
925149
@SuppressWarnings("unchecked")
  private static <Type extends Message> Type copyAsType(
      final Type typeDefaultInstance, final Message source) {
    return (Type)typeDefaultInstance.newBuilderForType()
                                    .mergeFrom(source)
                                    .build();
  }
1287620
function Callback (retType, argTypes, abi, func) {
  debug('creating new Callback');

  if (typeof abi === 'function') {
    func = abi;
    abi = undefined;
  }

  // check args
  assert(!!retType, 'expected a return "type" object as the first argument');
  assert(Array.isArray(argTypes), 'expected Array of arg "type" objects as the second argument');
  assert.equal(typeof func, 'function', 'expected a function as the third argument');

  // normalize the "types" (they could be strings, so turn into real type
  // instances)
  retType = ref.coerceType(retType);
  argTypes = argTypes.map(ref.coerceType);

  // create the `ffi_cif *` instance
  const cif = CIF(retType, argTypes, abi);
  const argc = argTypes.length;

  const callback = _Callback(cif, retType.size, argc, errorReportCallback, (retval, params) => {
    debug('Callback function being invoked')
    try {
      const args = [];
      for (var i = 0; i < argc; i++) {
        const type = argTypes[i];
        const argPtr = params.readPointer(i * ref.sizeof.pointer, type.size);
        argPtr.type = type;
        args.push(argPtr.deref());
      }

      // Invoke the user-given function
      const result = func.apply(null, args);
      try {
        ref.set(retval, 0, result, retType);
      } catch (e) {
        e.message = 'error setting return value - ' + e.message;
        throw e;
      }
    } catch (e) {
      return e;
    }
  });

  return callback;
}
883038
function Event(type) {
      var event = this;
      if (type instanceof Event) {
        return type;
      }
      return (event instanceof Event)
        ? _.assign(event, { 'timeStamp': _.now() }, typeof type == 'string' ? { 'type': type } : type)
        : new Event(type);
    }
461629
@Override
    public void emit(Sink sink, DataType dataType, String header) {
    	logger.fine("Generating data type " + dataType.name + ".");
        sink.write(header);
        sink.write(ASTPrinter.print(dataType));
        sink.write("\n*/\n");

        sink.write(ASTPrinter.printComments("", commentProcessor.leftAlign(dataType.comments)));
        for (Annotation annotation : dataType.annotations) {
            sink.write(ASTPrinter.print(annotation));
            sink.write("\n");
        }
        if (dataType.constructors.size() == 1) {
            emitSingleConstructor(sink, dataType, header);
            
        } else {
            emitMultipleConstructor(sink, dataType, header);
        }
    }
311
function getMessageFromPackage(messageType, type, callback) {
  var packageName = getPackageNameFromMessageType(messageType);
  var messageName = getMessageNameFromMessageType(messageType);
  packages.findPackage(packageName, function(error, directory) {
    var filePath;
    filePath = path.join(directory, type, messageName + '.' + type);
    getMessageFromFile(messageType, filePath, type, callback);
  });
}
1334410
function createTransportClientType() {
    log.info("create websocket");
    // [ -Events- ]
    // open - when the transport is open
    // close - when transport is closed
    // message - when transport receives a JSON message
    // [ -Constructor- ]
    function TransportClient() {
        log.info("instantiate websocket");
        // get non-ambiguous this
        var self = this;
        // Call parent constructor
        TransportClient.super_.call(self);
        // Internal structures
        self._ws = undefined;
        self._id = _.uniqueId(); // debugging tool only
        self._state = "NOT_OPENED";
        // state listeners
        self.once("open", function handleOpened() {
            self._state = "OPEN";
        }).once("close", function handleClosed() {
            self._state = "CLOSED";
        });
        // constructor - return undefined
        return undefined;
    }
    // [ -Inheritance- ]
    util.inherits(TransportClient, events.EventEmitter);
    // [ -Private API- ]
    // handle a received message
    // emits 'message' with a JSON argument
    TransportClient.prototype._handleMessage = function transportClientHandleMessage(message, flags) {
        log.info("websocket on message");
        // binay messages are not supported
        if (flags.binary) {
            var error = new VError("Got binary message from remote hub (not supported).");
            error.hubMessage = message;
            // emit error because this occurred asynchronously, and not necessarily due to user or local
            // programmer error
            this.emit('error', error);
        } else {
            // try to structure the message
            var structured;
            try {
                structured = JSON.parse(message);
            } catch (e) {
                var error = new VError(e, "cannot parse message from remote hub as JSON");
                error.hubMessage = message;
                // emit error because this occurred asynchronously, and not necessarily due to user or local
                // programmer error
                this.emit('error', error);
                // need to return here, because js has no try/catch/else,
                // and we don't want to continue after this error.
                return null;
            }
            // else - a non-binary well-formatted JSON message
            this.emit("message", structured);
        }
        // allow chaining
        return this;
    };
    // proxy events from the websocket
    TransportClient.prototype._proxyEvents = function transportClientProxyEvents() {
        this._ws.on('open', this.emit.bind(this, 'open'));
        this._ws.on('close', this.emit.bind(this, 'close'));
        this._ws.on('error', this.emit.bind(this, 'error'));
        // handle messages from remote hub
        this._ws.on("message", this._handleMessage.bind(this));
        // allow chaining
        return this;
    };
    // [ -Public API- ]
    // connect to a remote websocket hub
    // callback is called when the client is connected to the hub
    TransportClient.prototype.connect = function transportClientConnect(url, cb) {
        log.info("websocket client connect");
        // only allow this to be called once on the object
        if (this._ws) {
            // throw immediately - this is programmer error
            throw new VError("'connect' has already been called on this transport object.");
        }
        // add cb to listeners
        if (cb) {
            this.on('open', cb);
        }
        // open a websocket connection
        this._ws = new ws(url);
        // proxy some events
        this._proxyEvents();
        // it doesn't make sense to do anything with the object until connect
        // calls back, so return null
        return null;
    };
    // wrap a websocket conn in a Transport Client
    TransportClient.prototype.wrap = function transportClientWrap(websocketConnection) {
        log.info("websocket client wrap");
        var wsc = websocketConnection;
        // only allow this to be called once on the object
        if (this._ws) {
            // throw immediately - this is programmer error
            throw new VError("'connect' has already been called on this transport object.");
        }
        // theoretically the connection is already open
        this._ws = wsc;
        if (this._ws.readyState === ws.OPEN) {
            this._state = "OPEN";
        } else {
            var error = new VError("must only wrap websockets which are OPEN");
            error.state = ws.readyState;
            throw error;
        }
        // proxy some events
        this._proxyEvents();
        // allow chaining
        return this;
    };
    // close connection
    TransportClient.prototype.close = function transportClientClose() {
        log.info("websocket close");
        if (this._state !== "OPEN") {
            throw new VError("Cannot close a client which is not open");
        }
        this._ws.close();
        // it doesn't make sense to do anything with the object
        // after close, so return null
        return null;
    };
    // send to remote websocket
    TransportClient.prototype.send = function transportClientSend(message, cb) {
        log.info("websocket send", message);
        if (this._state !== "OPEN") {
            throw new VError("Nonsensical to call before 'open' or after 'close' events");
        }
        var stringified;
        try {
            stringified = JSON.stringify(message);
        } catch (e) {
            // do not use the cb to emit - this is a programmer error - throw immediately
            var error = new VError(e, "could not stringify JSON message");
            error.jsonMessage = message;
            throw error;
        }
        log.debug("stringified: ", stringified);
        // explicitly check state, because the ws module has bad
        // internal behavior if the socket is closing when you try
        // to send a message. see https://github.com/websockets/ws/issues/366
        if (this._ws.readyState === ws.OPEN) {
            this._ws.send(stringified, cb);
        } else {
            // throw - this is a programming error (sending while ws in bad state)
            throw new VError("The client connection is not open.  Cannot send.");
        }
        // allow chaining
        return this;
    };
    return TransportClient;
}
968039
function createChunk(type, data) {
	const length = typeof data != 'undefined' ? data.length : 0;
	const chunk = Buffer.alloc(4 + 4 + length + 4);

	chunk.writeUInt32BE(length, 0);
	chunk.fill(type, 4, 8, 'utf8');
	if (typeof data != 'undefined') {
		chunk.fill(data, 8, chunk.length - 4);
	}
	chunk.writeUInt32BE(crc32(chunk.slice(4, -4)), chunk.length - 4);

	return chunk;
}
1055387
function Builder (data) {

  if (!(this instanceof Builder)) return new Builder(data);

  debug('new builder', data);

  events.EventEmitter.call(this);

  this.message = Message(data);

}
694592
function parse(msg) {
  let model;
  if (typeof msg === 'object') {
    // data is a MessageEvent not a raw string
    msg = msg.data;
  }

  if (msg.startsWith(PullMessage.TYPE)) {
    // pull
    return new PullMessage();
  }

  if (msg.startsWith(RegisteredMessage.TYPE)) {
    // registered ack
    return new RegisteredMessage();
  }

  if (msg.startsWith(PushMessage.TYPE + '/')) {
    // push/modelStr
    model = msg.substring(PushMessage.TYPE.length + 1);
    return new PushMessage(model);
  }

  if (msg.startsWith(PushKevSMessage.TYPE + '/')) {
    // push/kevsStr
    model = msg.substring(PushKevSMessage.TYPE.length + 1);
    return new PushKevSMessage(model);
  }

  if (msg.startsWith(RegisterMessage.TYPE)) {
    // register/nodeName/modelStr
    const payload = msg.substring(RegisterMessage.TYPE.length + 1);
    let index = 0;
    let ch = payload.charAt(index);
    while (index < payload.length && ch !== '/') {
      index++;
      ch = payload[index];
    }
    const nodeName = payload.substring(0, index);
    return new RegisterMessage(nodeName, payload.substring(index + 1));
  }

  return null;
}
927039
function(friendnum, type, message) {
  this.type = 'FriendMessageEvent';
  this._friendnum = friendnum;
  this._message = message;
  this._messageType = type;
}
1131670
function(type, messages) {
  if (type !== CONSTS.LOG) {
    messages.unshift(tag(type));
  }
  
  return messages.map(styles.bind(null, type));
}
631039
function createEvent (type, data) {
  let event = document.createEvent(specialEvents[type] || 'Event')
  event.initEvent(type, true, true)
  data && (event.data = data)
  return event
}
696002
function generateProp(type, defaultVal) {
        if ( type === void 0 ) type = [Boolean, String, Number];
        if ( defaultVal === void 0 ) defaultVal = null;

        return {
            default: defaultVal,
            type: type
        }
    }
752831
function (message, data) {
                var datastr = data === undefined ? "no-data" : inspect(data);
                logfn(format(" [EMIT] %s %s", pad(message), datastr));
                EEProto.emit.apply(this, arguments);
            }
591674
function(data, type, useLBR) {
        // Re-create the encoder if LBR mode has changed.
        if ((useLBR !== undefined) && (this.lbr !== useLBR)) {
            this.lbr = useLBR;
            this.encoder = new FskEncoder(this.rate, this.lbr);
        }

        var bufLen = Math.ceil(data.length * 8 * this.encoder.samplesPerBit());
        var modulatedData = new Float32Array(bufLen);
        if (type === undefined) {
            type = 16;
        }

        this.encoder.modulate(data, modulatedData); // writes outputFloatArray in-place

        if (type === 16) {
            var pcmData = new Int16Array(modulatedData.length);
            for (var i = 0; i < modulatedData.length; i++) {
                // Map -1 .. 1 to -32767 .. 32768
                pcmData[i] = Math.round((modulatedData[i]) * 32767);
            }
            return pcmData;
        } else {
            var pcmData = new Uint8Array(new ArrayBuffer(modulatedData.length * 2));
            for (var i = 0; i < modulatedData.length; i++) {
                // Map -1 .. 1 to -32767 .. 32768
                var sample = Math.round((modulatedData[i]) * 32767);

                // Javascript doesn't really do two's compliment
                if (sample < 0)
                    sample = (0xffff - ~sample);

                pcmData[(i * 2) + 0] = Math.round(sample) & 0xff;
                pcmData[(i * 2) + 1] = Math.round(sample >> 8) & 0xff;
            }
            return pcmData;
        }
    }
826113
public static GraphEntity[] generateEntitiesOfType(String type,
            Browser browser) throws NotInitialised {
        Graph[] gs = browser.getGraphs();
        Sequences p = new Sequences();
        GraphEntity[] ges = browser.getAllEntities();
        HashSet actors = new HashSet();
        for (int k = 0; k < ges.length; k++) {
            if (ges[k].getType().equals(type)) {
                actors.add(ges[k]);
            }
        }
        return toGEArray(actors.toArray());
    }