Receive raw data into the payload

@param string $data
@return void
@throws PayloadException
778191
public function receiveData(string $data): void
    {
        $chunkSize = null;

        while ($data) {
            $frame = $this->getReceivingFrame();

            $remaining = $frame->getRemainingData();

            if ($remaining === null) {
                $chunkSize = 2;
            } elseif ($remaining > 0) {
                $chunkSize = $remaining;
            }

            $chunkSize = min(strlen($data), $chunkSize);
            $chunk = substr($data, 0, $chunkSize);
            $data = substr($data, $chunkSize);

            $frame->receiveData($chunk);
        }
    }
583108
private function send($data)
	{
		$rawMessage = json_encode($data);
		$payload = new WebsocketPayload;
		$payload->setOpcode(WebsocketPayload::OPCODE_TEXT)
				->setMask(TRUE)
				->setPayload($rawMessage);
		$encoded = $payload->encodePayload();
		fwrite($this->fd, $encoded);

		return $this;
	}
963989
public function decode(string $data)
    {
        try {
            return eval('return ' . $data . ';');
        } catch (\ParseError $e) {
            throw new DecodeException($e->getMessage(), $e->getCode(), $e);
        }

    }
1324206
public function bufferWrite(string $data): Promise
    {
        if ($this->append_after) {
            $this->append_after -= strlen($data);
            if ($this->append_after === 0) {
                $data .= $this->append;
                $this->append = '';
            } elseif ($this->append_after < 0) {
                $this->append_after = 0;
                $this->append = '';

                throw new Exception('Tried to send too much out of frame data, cannot append');
            }
        }

        return $this->write_buffer->bufferWrite(@$this->encrypt->encrypt($data));
    }
609848
public function setData($data)
    {
        if (!is_string($data)) {
            $data = json_encode($data);
        }

        $this->data = $data;
    }
1012525
private function send($payload)
    {
        $msg = $payload."\r\n";
        $len = strlen($msg);
        while (true) {
            $written = @fwrite($this->streamSocket, $msg);
            if ($written === false) {
                throw new \Exception('Error sending data');
            }

            if ($written === 0) {
                throw new \Exception('Broken pipe or closed connection');
            }

            $len = ($len - $written);
            if ($len > 0) {
                $msg = substr($msg, (0 - $len));
            } else {
                break;
            }
        }

        if ($this->debug === true) {
            printf('>>>> %s', $msg);
        }
    }
837896
public function write(string $data) : void
    {
        $this->buffer .= $data;

        if (strlen($this->buffer) >= $this->size) {
            $this->flush();
        }
    }
356963
protected function handleReady($data)
    {
        $this->logger->debug('ready packet received');

        // If this is a reconnect we don't want to
        // reparse the READY packet as it would remove
        // all the data cached.
        if ($this->reconnecting) {
            $this->reconnecting = false;
            $this->logger->debug('websocket reconnected to discord through identify');

            return;
        }

        $content = $data->d;
        $this->emit('trace', $data->d->_trace);
        $this->logger->debug('discord trace received', ['trace' => $content->_trace]);

        // Setup the user account
        $this->client    = $this->factory->create(Client::class, $content->user, true);
        $this->sessionId = $content->session_id;

        $this->logger->debug('client created and session id stored', ['session_id' => $content->session_id, 'user' => $this->client->user->getPublicAttributes()]);

        // Private Channels
        $private_channels = new PrivateChannelRepository(
            $this->http,
            $this->cache,
            $this->factory
        );

        if ($this->options['pmChannels']) {
            foreach ($content->private_channels as $channel) {
                $channelPart = $this->factory->create(Channel::class, $channel, true);
                $this->cache->set("pm_channels.{$channelPart->recipient->id}", $channelPart);
                $private_channels->push($channelPart);
            }

            $this->logger->info('stored private channels', ['count' => $private_channels->count()]);
        } else {
            $this->logger->info('did not parse private channels');
        }

        $this->private_channels = $private_channels;

        // Guilds
        $this->guilds = new GuildRepository(
            $this->http,
            $this->cache,
            $this->factory
        );
        $event = new GuildCreate(
            $this->http,
            $this->factory,
            $this->cache,
            $this
        );

        $unavailable = [];

        foreach ($content->guilds as $guild) {
            $deferred = new Deferred();

            $deferred->promise()->then(null, function ($d) use (&$unavailable) {
                list($status, $data) = $d;

                if ($status == 'unavailable') {
                    $unavailable[$data] = $data;
                }
            });

            $event->handle($deferred, $guild);
        }

        $this->logger->info('stored guilds', ['count' => $this->guilds->count()]);

        if (count($unavailable) < 1) {
            return $this->ready();
        }

        // Emit ready after 60 seconds
        $this->loop->addTimer(60, function () {
            $this->ready();
        });

        $function = function ($guild) use (&$function, &$unavailable) {
            if (array_key_exists($guild->id, $unavailable)) {
                unset($unavailable[$guild->id]);
            }

            // todo setup timer to continue after x amount of time
            if (count($unavailable) < 1) {
                $this->logger->info('all guilds are now available', ['count' => $this->guilds->count()]);
                $this->removeListener(Event::GUILD_CREATE, $function);

                $this->setupChunking();
            }
        };

        $this->on(Event::GUILD_CREATE, $function);
    }
1277685
protected function handlePost($data)
    {
        PWELogger::debug($_SERVER['REQUEST_METHOD'] . ": %s", $data);
        throw new HTTP5xxException('Not supported method for this call: ' . $_SERVER['REQUEST_METHOD'], HTTP5xxException::UNIMPLEMENTED);
    }
1151235
public function sendData($data)
    {
        try {
            $response = $this->httpClient->post(
                $this->getEndpoint(),
                $this->getRequestHeaders(),
                json_encode($data)
            )->send();

            return new TokenPurchaseResponse($this, $response->json());
        } catch (BadResponseException $e) {
            $response = $e->getResponse();

            return new TokenPurchaseResponse($this, $response->json());
        }
    }
1311131
public function sendBuffer($data)
    {
        if (! $this->ready) {
            return;
        }

        $packet = new VoicePacket($data, $this->ssrc, $this->seq, $this->timestamp, true, $this->secret_key);
        $this->client->send((string) $packet);

        $this->streamTime = microtime(true);

        $this->emit('packet-sent', [$packet]);
    }
751604
public function fillRawData(string $rawData): TelegramResponse
    {
        $this->rawData = $rawData;
        $this->decodedData = json_decode($this->rawData, true);

        if ($this->decodedData['ok'] === false) {
            $exception = new ClientException();
            $exception->setError(new UnsuccessfulRequest($this->decodedData));
            throw $exception;
        }

        return $this;
    }
694916
public function setData($data) {
        if (!empty($data)) {
            foreach($data as $key=>$value) {
                $this->_data[$key] = $value;
            }
        } else {
            $this->_data = array();
        }
    }
594328
public function sendData($data)
    {
        $httpResponse = $this->httpClient->post(
            $this->getEndpoint(),
            ['Content-Type' => 'text/xml; charset=utf-8'],
            $this->xmlSerialize($data)
        )->send();

        return $this->response = $this->newResponse( $httpResponse->xml() );
    }
272060
public function parseChunk($data)
    {
        if (!$data) {
            return;
        }
        // Detect end of transfer
        if ($end = strpos($data, "0\r\n\r\n")) {
            $data = substr($data, 0, $end);
        }
        $this->buffer.= $data;
        $this->request->onData($data);

        if ($end) {
            $this->buffer = $this->parseChunkedBuffer($this->buffer);
            $this->request->setBody($this->buffer);
            $this->notifyCompleted();
            $this->buffer = '';
        }
    }
517315
protected function send($data)
    {
        $pos = $this->tell();

        // Add data to the end of the buffer.
        $this->seek(0, SEEK_END);
        $this->write($data);
        if ($pos !== false) {
            // Rewind so that read() can later read this data.
            $this->seek($pos);
        }
    }
1117736
public function write($data)
    {
        if ($this->closed) {
            return;
        }

        $all = $this->tail . $data;
        $messages = $this->getParser()->consumeAll($all);
        $this->tail = $all;

        foreach ($messages as $message) {
            if (isset($message['message'])) {
                $this->emit('data', array($message['message']));
                $this->emit('irc.received', array($message));
            } elseif (isset($message['invalid'])) {
                $this->emit('invalid', array($message['invalid']));
            }
        }
    }