Called when new frame is received
@param string $data Frame's contents
@param integer $type Frame's type
@return void
330658
public function onFrame($data, $type)
    {
        foreach (explode("\n", $data) as $pct) {
            if ($pct === '') {
                continue;
            }
            $this->onPacket(json_decode($pct, true));
        }
    }
452527
public function onSwooleWSMessage($server, $frame)
    {
        $this->onSwooleWSAllMessage($server, $frame->fd, $frame->data);
    }
421774
public function onAddedToType(TypeInterface &$type)
    {
        parent::onAddedToType($type);

        if ($this->getAddIndex()) {
            $type->addIndex(new Index($this->name));
        }

        $type->addTrait(UpdatedAtInterface::class, UpdatedAtInterfaceImplementation::class)->serialize($this->name);
    }
82478
public function sendFrame($data, $type = null, $cb = null)
    {
        $this->realConn->sendFrame('a' . $this->toJson([$data]), $type, $cb);
        return true;
    }
1280037
protected function processControlFrame(WebSocketFrame $frame)
    {
        switch ($frame->getType()) {
            case WebSocketOpcode::CloseFrame :
                $this->logger->notice("Got CLOSE frame");

                $frame = WebSocketFrame::create(WebSocketOpcode::CloseFrame);
                $this->sendFrame($frame);

                $this->_socket->close();
                break;
            case WebSocketOpcode::PingFrame :
                $frame = WebSocketFrame::create(WebSocketOpcode::PongFrame, $frame->getData());
                $this->sendFrame($frame);
                break;
        }
    }
512105
public function onMessage($server, $frame)
    {
        // execute parser strategies and skip non-message packet
        if ($this->payloadParser->execute($server, $frame)) {
            return;
        }

        /** @var Websocket $websocket */
        $websocket = $this->app->make(Websocket::class);
        /** @var Sandbox $sandbox */
        $sandbox = $this->app->make(Sandbox::class);

        try {
            // decode raw message via parser
            $payload = $this->payloadParser->decode($frame);

            $websocket->reset(true)->setSender($frame->fd);

            // enable sandbox
            $sandbox->init();

            // dispatch message to registered event callback
            ['event' => $event, 'data' => $data] = $payload;
            $websocket->eventExists($event)
                ? $websocket->call($event, $data)
                : $this->websocketHandler->onMessage($frame);
        } catch (Throwable $e) {
            $this->logServerError($e);
        } finally {
            // disable and recycle sandbox resource
            $sandbox->clear();
        }
    }
17345
public function setType($type = self::TYPE_TEXT) {
		if (!in_array($type, array(self::TYPE_TEXT, self::TYPE_HTML))) {
			throw new MailException('invalid type: ' . $type);
		}
		$this->type = $type;
	}
341276
protected function handleClientCloseFrame(NetworkFrame $frame)
    {
        $this->logger->debug("Client sent close frame, parsing");

        //TODO strict
        $code = $frame->getPayloadPart(0, 2);

        if (!empty($code)) { //Code is optional BUT it can't be 0
            if (!isset($code[1])) { // payload have to be at least 2 bytes
                throw new WebSocketException("Invalid closing payload", DataFrame::CODE_PROTOCOL_ERROR);
            }

            $code = unpack("n", $code);
            $code = $code[1]; //Array dereference on call is allowed from 5.4
            $this->logger->debug("Client disconnected with code: " . $code);

            if (!DataFrame::validateCloseCode($code)) {
                throw new WebSocketException("Invalid close code", DataFrame::CODE_PROTOCOL_ERROR);
            }

            if (!mb_check_encoding($frame->getPayloadPart(2), 'UTF-8')) {
                throw new WebSocketException("Close frame payload is not valid UTF-8",
                    NetworkFrame::CODE_DATA_TYPE_INCONSISTENT);
            }
        }

        $this->logger->debug("Converting client close frame into server close frame");
        $frame->setOpcode(DataFrame::OPCODE_CLOSE);
        $frame->setMasking(false);
        $frame->setPayload(pack("n", DataFrame::CODE_CLOSE_NORMAL) . "Client closed connection");
        $this->pushData($frame);
        $this->disconnect();
    }
78908
public function setType($type)
    {
        if ($type instanceof PagSeguroPaymentMethodType) {
            $this->type = $type;
        } else {
            $this->type = new PagSeguroPaymentMethodType($type);
        }
    }
1359542
private void fireFrameType(CEMI frame, int type)
	{
		final FrameEvent e = new FrameEvent(this, frame);
		for (final Iterator i = listeners.iterator(); i.hasNext();) {
			final TransportListener l = (TransportListener) i.next();
			try {
				if (type == 0)
					l.broadcast(e);
				else if (type == 1)
					l.group(e);
				else if (type == 2)
					l.dataIndividual(e);
				else if (type == 3)
					l.dataConnected(e);
			}
			catch (final RuntimeException rte) {
				removeTransportListener(l);
				logger.error("removed event listener", rte);
			}
		}
	}
768627
private void fireFrameReceived(final KnxTunnelEmi emiType, final byte[] frame) throws KNXFormatException
	{
		logger.debug("received {} frame {}", emiType, DataUnitBuilder.toHex(frame, ""));
		final FrameEvent fe = emiType == KnxTunnelEmi.CEmi
				? new FrameEvent(this, CEMIFactory.create(frame, 0, frame.length)) : new FrameEvent(this, frame);
		listeners.fire(l -> l.frameReceived(fe));
	}
944511
@Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        if (msg instanceof Frame) {
            Frame frame = (Frame) msg;
            if (hasCurrentTransaction()) {
                String tid = currentDataFrameTransaction.getId();
                logger.trace("Received frame within transaction ({}) context: {}", tid, frame);

                // give new frame to current transaction
                NettyZWaveChannelContext zctx = new NettyZWaveChannelContext();
                if (currentDataFrameTransaction.addFrame(zctx, frame)) {
                    if (currentDataFrameTransaction.isComplete()) {
                        logger.trace("*** Data frame transaction ({}) completed", tid);
                        logger.trace("");
                        cancelTimeoutCallback();
                    }
                    zctx.process(ctx);
                // if transaction didn't consume frame, then pass it down the pipeline
                } else {
                    logger.trace("Transaction ignored frame so passing it along");
                    ctx.fireChannelRead(msg);
                }
            } else if (msg instanceof AddNodeToNetwork) {
                logger.trace("Received ADD_NODE_STATUS_NODE_FOUND; starting transaction");
                NettyZWaveChannelContext zctx = new NettyZWaveChannelContext();
                currentDataFrameTransaction = new NodeInclusionTransaction(zctx, (DataFrame)msg);
                zctx.process(ctx);
            } else {
                logger.trace("Received frame outside of transaction context so passing it along: {}", frame);
                ctx.fireChannelRead(msg);
            }
        }
    }
672934
public function onMessage(Server $server, Frame $frame)
    {
        $fd = $frame->fd;

        // init fd and coId mapping
        WebSocketContext::setFdToCoId($fd);

        App::trigger(WsEvent::ON_MESSAGE, null, $server, $frame);

        $this->log("received message: {$frame->data} from fd #{$fd}, co ID #" . Coroutine::tid(), [], 'debug');

        /** @see Dispatcher::message() */
        \bean('wsDispatcher')->message($server, $frame);

        // delete coId to fd mapping
        WebSocketContext::delFdByCoId();
        RequestContext::destroy();
    }
986411
public function asType(Type $type)
    {
        if ($this->nullable) {
            $type = $type->nullable();
        }

        $this->invokeCallback($type);

        if ($this->indexName) {
            if ($this->isUnique) {
                $this->definition->unique($this->indexName)->on($this->name);
            } else {
                $this->definition->index($this->indexName)->on($this->name);
            }
        }
    }
732518
protected function checkEnd($type, $data)
    {
        $lastTag = array_pop($this->stack);

        if (!is_array($lastTag)) {
            throw new Exceptions\OutputGeneratorException(
                sprintf(
                    'Invalid close: Trying to close on empty stack.'
                )
            );
        }

        if (array($lastTag[0], $lastTag[1]) !== array($type, $data)) {
            throw new Exceptions\OutputGeneratorException(
                sprintf(
                    'Invalid close: Trying to close %s:%s, while last element was %s:%s.',
                    $type,
                    $data,
                    $lastTag[0],
                    $lastTag[1]
                )
            );
        }
    }
630560
protected function init($request, $builder, $type = 'builder')
    {
        $this->request    = $request;
        $this->query_type = $type;
        $this->columns    = $builder->columns;
        $this->connection = $builder->getConnection();
        $this->prefix     = $this->connection->getTablePrefix();
        $this->database   = $this->connection->getDriverName();
        if ($this->isDebugging()) {
            $this->connection->enableQueryLog();
        }
    }
378381
public function write($data): void
    {
        $rand = \random_int(0, 28);
        $frame = [
            'fin' => 1,
            'rsv1' => 0,
            'rsv2' => 0,
            'rsv3' => 0,
            'opcode' => 1, // We always send text
            'mask' => 1,
            'len' => \strlen($data),
            'mask_key' => \substr(\md5(\uniqid()), $rand, 4),
            'data' => $data,
        ];

        if (1 === $frame['mask']) {
            for ($i = 0; $i < $frame['len']; ++$i) {
                $frame['data'][$i]
                    = \chr(\ord($frame['data'][$i]) ^ \ord($frame['mask_key'][$i % 4]));
            }
        }

        if ($frame['len'] > 2 ** 16) {
            $len = 127;
        } elseif ($frame['len'] > 125) {
            $len = 126;
        } else {
            $len = $frame['len'];
        }

        $firstByte = ($frame['fin'] << 7) | (($frame['rsv1'] << 7) >> 1) | (($frame['rsv2'] << 7) >> 2) | (($frame['rsv3'] << 7) >> 3) | (($frame['opcode'] << 4) >> 4);
        $secondByte = ($frame['mask'] << 7) | (($len << 1) >> 1);

        $this->socketWrite(\chr($firstByte));
        $this->socketWrite(\chr($secondByte));

        if (126 === $len) {
            $this->socketWrite(\pack('n', $frame['len']));
        } elseif (127 === $len) {
            $higher = $frame['len'] >> 32;
            $lower = ($frame['len'] << 32) >> 32;
            $this->socketWrite(\pack('N', $higher));
            $this->socketWrite(\pack('N', $lower));
        }

        if (1 === $frame['mask']) {
            $this->socketWrite($frame['mask_key']);
        }

        $this->socketWrite($frame['data']);
    }