Parse the raw data
@param $data String the raw data to parse (minus packet ID and packet length
@throws InvalidDataException
176077
function fromRawData($data)
    {
        $versionVarInt = VarInt::readUnsignedVarInt($data);
        $data = substr($data, $versionVarInt->getDataLength());

        $addressStringLength = VarInt::readUnsignedVarInt($data);
        $data = substr($data, $addressStringLength->getDataLength());

        $address = substr($data, 0, $addressStringLength->getValue());
        $data = substr($data, $addressStringLength->getValue());

        $portShort = unpack('nshort', substr($data, 0, 2))['short'];
        $data = substr($data, 2);

        $nextVarInt = VarInt::readUnsignedVarInt($data);

        try {
            $nextStage = Stage::get($nextVarInt->getValue());

            //disconnect if not a valid stage
            if ($nextStage != Stage::LOGIN() && $nextStage != Stage::STATUS()) {
                throw new InvalidDataException('Stage must be LOGIN or STATUS on handshake');
            }

            //set all of the data
            $this->setNextStage($nextStage)
                ->setServerPort($portShort)
                ->setProtocolVersion($versionVarInt->getValue())
                ->setServerAddress($address);
        } catch (InvalidArgumentException $ex) {
            throw new InvalidDataException('Stage is not a valid number');
        }
    }
362584
public function parseData()
    {
        $headers = $this->getHeaders();

        if (!in_array($this->httpRequest->getMethod(), ['PUT', 'POST'])) {
            return $this->emit('end');
        }

        $this->httpRequest->on('data', function($data) use ($headers, &$dataResult) {
            $dataResult .= $data;

            if (isset($headers["content-length"])) {
                if (strlen($dataResult) == $headers["content-length"][0]) {
                    $this->httpRequest->close();
                }
            } else {
                $this->httpRequest->close();
            }
        });

        $this->httpRequest->on('end', function() use (&$dataResult) {
            $this->onEnd($dataResult);
        });
    }
482792
public function loadArray($data)
    {
        if (\is_string($data) && is_file($data)) {
            $data = require $data;
        }

        if (!\is_array($data)) {
            throw new \InvalidArgumentException('param type error! must is array.');
        }

        return $this->bindData($this->data, $data);
    }
1198947
function parse($data)
    {
        $_header = strstr($data, self::HTTP_EOF, true);
        if ($_header === false)
        {
            $this->buffer = $data;
        }
        $header = self::parseHeader($_header);
        if ($header === false)
        {
            $this->isError = true;
        }
        $this->header = $header;
        return $header;
    }
397458
private function parseUI24($data)
    {
        if (!isset($data[2])) {
            throw new UnexpectedValueException();
        }
        $unpacked = unpack('N', "\x00" . $data);

        return array_shift($unpacked);
    }
194955
protected function getDataSetFromString(string $data) : DataSet
    {
        if (strpos($data, "\n") === false) {
            throw new ParserRuntimeException('The data could not be parsed (no pattern found).', 1459589758);
        }

        if (strpos($data, "\r\n") !== false) {
            // if the source file was created under windows, replace the line endings
            $data = str_replace("\r\n", "\n", $data);
        }

        // Prepare the data from the data set
        list($pattern, $properties) = explode("\n", $data, 2);
        $pattern = substr($pattern, 1, -1);

        $properties = @parse_ini_string($properties);
        if ($properties === false) {
            throw new ParserRuntimeException(
                "The data could not be parsed (invalid properties for pattern '$pattern').",
                1459589759
            );
        }

        $dataSet = new DataSet($pattern);
        $dataSet->setProperties($properties);

        return $dataSet;
    }
84018
public function decrypt($data)
    {
        $data = json_decode(base64_decode($data), true);

        $iv = base64_decode($data['iv']);

        if (!$this->isEncryptedDataValid($data)) {
            throw new Exception('The given encrypted data is invalid.');
        }
        if (!$this->isMacValid($data, 16)) {
            throw new Exception('The hash is invalid.');
        }
        /**
         * try to decrypt.
         */
        $decrypted = \openssl_decrypt(
            $data['value'], $this->cipher, $this->key, 0, $iv
        );

        /*
         * throw exception is we cannot decrypt
         */
        if ($decrypted === false) {
            throw new Exception('Data could not be decrypted.');
        }

        return $decrypted;
    }
1336973
public function data($data=''){
        if('' === $data && !empty($this->data)) {
            return $this->data;
        }
        if(is_object($data)){
            $data   =   get_object_vars($data);
        }elseif(is_string($data)){
            parse_str($data,$data);
        }elseif(!is_array($data)){
            E(L('_DATA_TYPE_INVALID_'));
        }
        $this->data = $data;
        return $this;
    }
945032
public function onData($data)
    {
        //if we're in encryption stage decrypt it first
        if($this->secret !== null) {
            mcrypt_generic_init($this->encryptor, $this->secret, $this->secret);
            $data = mdecrypt_generic($this->encryptor, $data);
            mcrypt_generic_deinit($this->encryptor);
        }

        //attempt to parse the data as a packet
        try {

            //add the data to the current buffer
            $this->packetBuffer .= $data;

            //for as long as we have data left in the buffer
            do {

                //read the packet length from the stream
                $packetLengthVarInt = VarInt::readUnsignedVarInt($this->packetBuffer);

                //not enough data to read the packet length, wait for more data
                if($packetLengthVarInt === false) {
                    return;
                }

                //total length of the packet is the length of the varint + it's value
                $totalLength = $packetLengthVarInt->getDataLength() + $packetLengthVarInt->getValue();

                //if we don't have enough data to read the entire packet wait for more data to enter
                $bufferLength = strlen($this->packetBuffer);
                if ($bufferLength < $totalLength) {
                    return;
                }

                //remove the packet length varint from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getDataLength());

                //read the packet ID from the buffer
                $packetDataWithPacketID = substr($this->packetBuffer, 0, $packetLengthVarInt->getValue());

                //remove the rest of the packet from the buffer
                $this->packetBuffer = substr($this->packetBuffer, $packetLengthVarInt->getValue());

                //read the packet ID
                $packetID = VarInt::readUnsignedVarInt($packetDataWithPacketID);

                //get the raw packet data
                $packetData = substr($packetDataWithPacketID, $packetID->getDataLength());

                $this->lastPacket = $this->currentTime();

                //trigger packet processing
                $this->processPacket($packetID->getValue(), $packetData);

                //if we have buffer left run again
            } while (strlen($this->packetBuffer) > 0);

            //if any exceptions are thrown (error parsing the packets e.t.c.) send a disconnect packet
        } catch (Exception $ex) {
            echo "EXCEPTION IN PACKET PARSING {$ex->getMessage()}\n";
            echo $ex->getTraceAsString();
            $dis = new DisconnectPacket();
            $dis->setReason('Internal Server Error: '.$ex->getMessage());
            $this->end($dis->encodePacket());
        }
    }
143069
public function addData($data) {
        if (\is_string($data)) {
            $this->addDataSql($data);
        } elseif (\is_array($data)) {
            $this->addDataArray($data);
        } elseif (\is_object($data)) {
            $this->addDataObjectCollection($data);
        } elseif (\is_resource($data)) {
            $this->addDataQueryResource($data);
        } else {
            throw new InvalidArgumentException('Unsupported data type.');
        }
        return $this;
    }
495069
private function parse(string $data = "")
    {
        try {
            $promise = $this->requestParser->send($data);

            if ($promise instanceof Promise && !$this->isExported && !($this->status & self::CLOSED_RDWR)) {
                // Parser wants to wait until a promise completes.
                $this->paused = true;
                $promise->onResolve($this->resume); // Resume will set $this->paused to false if called immediately.
                if ($this->paused) { // Avoids potential for unnecessary disable followed by enable.
                    Loop::disable($this->readWatcher);
                }
            }
        } catch (\Throwable $exception) {
            // Parser *should not* throw an exception, but in case it does...
            $this->logger->critical($exception);
            $this->close();
        }
    }
519597
public function decode($data)
    {
        $parser = new Parser();
        $this->arrayData = (array) $parser->parse($data);
        return $this->arrayData;
    }
397951
public function setData($data)
    {
        if ((is_string($data) === true && $data === '') || Format::isUri($data) === true) {
            $this->data = $data;
        } else {
            $msg = "The 'data' argument must be a URI or an empty string, '" . gettype($data) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
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);
        }
    }
1192805
public function parseContentLength($data)
    {
        $this->request->onData($data);
        $this->buffer.= $data;

        if (strlen($this->buffer) >= $this->contentLength) {
            $this->buffer = "";
            $this->notifyCompleted();
        }
    }
1045880
public static function readUnsignedVarInt($data)
    {
        $fd = fopen('data://text/plain,' . urlencode($data), 'rb');

        $original = '';
        $result = $shift = 0;
        do {
            $readValue = self::read($fd, 1);
            if(false === $readValue || $readValue === null) {
                return false;
            }
            $original .= $readValue;
            $byte = ord($readValue);
            $result |= ($byte & 0x7f) << $shift++ * 7;

            if($shift > 5) {
                throw new InvalidDataException('VarInt greater than allowed range');
            }
        } while ($byte > 0x7f);

        return new VarInt($result, $original, $shift);
    }
1185083
public static function decode(string $data): string
    {
        $decoded = base64_decode(strtr($data, '-_', '+/'), true);
        if (false === $decoded) {
            throw new InvalidArgumentException('Invalid data provided');
        }

        return $decoded;
    }