Deserialize an incoming response into a protobuf message

@param string $response
@param string $expectedMessageClass
@return Message
@throws SerializationException
@throws \Google\Protobuf\Internal\Exception
323605
public function deserialize(string $response, string $expectedMessageClass)
    {
        try {
            /** @var Message $expectedMessage */
            $expectedMessage = new $expectedMessageClass();
            $expectedMessage->mergeFromString($response);
            return $expectedMessage;
        } catch (\Exception $e) {
            throw new SerializationException(
                'Could not deserialize message from nghttpx response body due to protobuf error'
            );
        }
    }
246645
public function assertInstanceOf($expected, $message = '')
    {
        Assert::assertInstanceOf($expected, $this->getData(), $message);

        return $this;
    }
514176
protected function unserializeResponse($response = null){
        switch($this->getEndpoint()){
            case "json":
                return json_decode($response,true);
                break;
            case "xml":
                return (array) json_decode(json_encode(simplexml_load_string($response, null, LIBXML_NOCDATA)),true);
                break;
            default:
                throw new \ErrorException('Invalid response type');
                break;
        }
    }
783867
protected function serializeResponse($response)
    {
        /** @var ResponseInterface $response */
        $serialized = serialize([
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody()->getContents(),
        ]);

        //subsequent calls need to access the stream from the beginning
        $response->getBody()->rewind();

        return $serialized;
    }
47257
private function _processGatewayResponse($response, $expectedType)
    {
        $gatewayRspCode = (isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null);
        $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);

        if ($gatewayRspCode == '0') {
            return;
        }

        if ($gatewayRspCode == '30') {
            try {
                $this->void($transactionId);
            } catch (Exception $e) {
                throw new HpsGatewayException(
                    HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR,
                    'Error occurred while reversing a charge due to HPS gateway timeout',
                    $e,
                    null,
                    null,
                    $transactionId
                );
            }
        }

        HpsGatewayResponseValidation::checkResponse($response, $expectedType);
    }
480901
private function unserializeResponse($serialized, MessageFactoryInterface $messageFactory)
    {
        return $this->createResponse($this->unserialize($serialized), $messageFactory);
    }
1265813
public function assertInternalType($expected, $message = '')
    {
        Assert::assertInternalType($expected, $this->getData(), $message);

        return $this;
    }
195159
public static function invalidResponseBody(ResponseInterface $response, $expectedPath)
    {
        $response->getBody()->rewind();
        return new static(sprintf(
            "Response body '%s' is missing the expected JSON path '%s'",
            $response->getBody()->getContents(),
            $expectedPath
        ));
    }
670751
public function assertJsonStringEqualsJsonString($expectedJson, $message = '')
    {
        Assert::assertJsonStringEqualsJsonString($expectedJson, $this->getData(), $message);

        return $this;
    }
1296220
public function assertNotSameSize($expected, $message = '')
    {
        Assert::assertNotSameSize($expected, $this->getData(), $message);

        return $this;
    }
140023
protected function processResponse(Response $response, $expectedCode = 200)
	{
		if (202 == $response->code)
		{
			throw new \DomainException(
				'GitHub is building the statistics data. Please try again in a few moments.',
				$response->code
			);
		}

		return parent::processResponse($response, $expectedCode);
	}
501447
public function decryptResponse($response)
    {
        if (!is_string($response)) {
            return $response;
        }

        if ($this->usesEncryption()) {
            return json_decode(
                json_encode(
                    JWT::decode(
                        $response,
                        $this->encryptionKey,
                        array($this->encryptionAlgorithm)
                    )
                ),
                true
            );
        }

        throw EncryptionConfigurationException::undeterminedEncryption();
    }
437066
public static function createProtocolMessage(Message $msg)
    {
        $version = $msg->shift();
        if (!self::hasProtocolVersion(($version))) {
            throw new UnknownProtocolVersionException();
        }

        $type = $msg->shift();
        $class = self::getClassByType($type);

        return $class::fromMessage($msg);
    }
974452
protected function parseResponse($response)
    {
        $result = json_decode((string) $response->getBody(), true);

        if (isset($result['exception'])) {
            throw (new DelegationException($result['message']))->setException($result['exception']);
        }

        return $result;
    }
966262
public void doWithMessage(WebServiceMessage responseMessage) throws IOException, TransformerException {
        // convert and set response for later access via getResponse():
        response = endpointConfiguration.getMessageConverter().convertInbound(responseMessage, endpointConfiguration, context);
    }
138126
public function filterResponse(SimplifiedResponse $response)
    {
        if (isset($response->headers['content-type']) &&
            ($response->headers['content-type'] === 'application/json')) {
            if ($response->content === "") {
                $response->content = null;
                return;
            }

            $decoded = json_decode($response->content, true);
            if ($decoded === null) {
                throw new \UnexpectedValueException("Invalid JSON in JSON response: $response->content");
            }

            $response->content = $decoded;
        }

        return $response;
    }
583612
private function decodeResponse(ResponseInterface $response)
    {
        $string = (string) $response->getBody();
        $data = json_decode($string, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonDecodeException($string);
        }

        return $data;
    }