Send a Protobuf message and receive the response

@param \DrSlump\Protobuf\Message $message
@param integer                   $messageCode
@param integer                   $expectedResponseCode

@return \DrSlump\Protobuf\Message
971477
public function send(Message $message, $messageCode, $expectedResponseCode)
    {
        $payload  = $this->encodeMessage($message, $messageCode);
        $stream   = $this->connection->send($payload);

        return $this->receiveMessage($stream, $expectedResponseCode);
    }
1141662
protected function write(string $line, $expectedCode = null, string $message = null): void
    {
        \fwrite($this->connection, $line . Message::EOL);
        if ($expectedCode) {
            $response = $this->read();
            if (!\in_array((int) $response, (array) $expectedCode, true)) {
                throw new SmtpException('SMTP server did not accept ' . ($message ?: $line) . ' with error: ' . \trim($response));
            }
        }
    }
538645
public function respondDeleted($code = ApiResponse::CODE_DELETED, array $data = [], $message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_NO_CONTENT)->respond([
            'status' => [
                'type' => 'success',
                'message' => $this->getDefaultMessage($code, $message),
                'code' => $code,
                'http_code' => $this->getStatusCode(),
            ],
            'data' => $data,
        ]);
    }
754612
public function setRedirect($location, $message = null, $code = null)
     {
         $this->_redirect = null;

         if (! empty($location)) {

             $isCallable = is_callable(array($location, '__toString'));

             if (! is_string($location) && !is_numeric($location) && !$isCallable) {
                 throw new \UnexpectedValueException(
                    'The Response location must be a string or object implementing __toString(), "'.gettype($location).'" given.'
                );
             }

             if (! $code) {
                 $code = $this->_status_code;
             }

             $this->setStatus($code, $message);
             $this->setHeader('Location', $location);
         }

         return $this;
     }
855248
public function sendServiceCheck(string $host, string $service, int $returncode, string $message = null) : bool {
        if ('' === $service || "\0" === $service) {
            throw new \InvalidArgumentException('service can not be empty');
        }
        return $this->send($host, $service, $returncode, $message);
    }
613917
private function setNewResponse(GetResponseForExceptionEvent $event, $statusCode, $message = '')
    {
        $event->setResponse(new Response());
        $event->getResponse()->setStatusCode($statusCode, $message);
    }
30699
protected function generateResponse(
        int $code,
        string $reasonPhrase = ""
    ): ResponseInterface{
        return $this->getResponseFactory()
            ->createResponse($code, $reasonPhrase)
        ;
    }
448024
public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([
            'status' => [
                'type' => 'success',
                'message' => $this->getDefaultMessage($code, $message),
                'code' => $code,
                'http_code' => $this->getStatusCode(),
            ],
            'data' => $data,
        ]);
    }
69021
private function sendMessage($message, $successCodes = null, $errorMsg = null, $baseEncode = false) {
		$this->log($message);
		$getResponse = (bool) $successCodes;
		if ($baseEncode) $message = base64_encode($message);
		try {
			$response = $this->connection->sendMessage($message, $getResponse, self::EOL);
		} catch (SmtpConnectionException $ex) {
			$this->log($ex->getMessage(), 'server', true);
			throw $ex;
		}
		if (!$response) return null;
		
		$successCodes = is_array($successCodes) ? $successCodes : array($successCodes);
		if (!in_array($response->getCode(), $successCodes)) {
			$this->log($response, 'server', 1);
			throw new SmtpConnectionException($errorMsg);
		}
		$this->log($response);
		
		return $response;
	}
92224
public function close($replyCode = 0, $replyText = "")
    {
        if ($this->state === ChannelStateEnum::CLOSED) {
            throw new ChannelException("Trying to close already closed channel #{$this->channelId}.");
        }

        if ($this->state === ChannelStateEnum::CLOSING) {
            return $this->closePromise;
        }

        $this->state = ChannelStateEnum::CLOSING;

        $this->client->channelClose($this->channelId, $replyCode, $replyText, 0, 0);
        $this->closeDeferred = new Deferred();
        return $this->closePromise = $this->closeDeferred->promise()->then(function () {
            $this->client->removeChannel($this->channelId);
        });
    }
1201562
protected function sendResponseHeadersToClient(WebRequest $request, $code, $message)
    {
        $headers = [
            "Date"       => gmdate("D, d M Y H:i:s T"),
            "Connection" => "close"
        ];
        
        $bytes = $this->sendToClient($request->getVersion() . " {$code} {$message}\r\n");
        foreach($headers as $header => $value) {
            $bytes += $this->sendToClient("{$header}: {$value}\r\n");
        }
        $bytes += $this->sendToClient("\r\n");
        
        return $bytes;
    }
967739
public function yyerror( $message, $expected = null )
	{
		if ( ! is_null( $this->errorText ) && ! is_null( $expected ) && count( $expected ) > 0 )
		{
			$errorMsg = $message . ", expecting";
			for ( $n = 0; $n < count( $expected ); ++ $n )
				$errorMsg .= " " . $expected[ $n ];
			$this->errorText[] = "$errorMsg\n";
		} else
			$this->errorText[] = "$message\n";
	}
1022258
private function checkResponseCode($responseCode)
    {
        switch ($responseCode) {
            case self::REQUEST_HAS_SUCCEED_CODE:
                break;

            case self::MALFORMED_NOTIFICATION_CODE:
                throw new MalformedNotificationException(
                    "The request could not be parsed as JSON, or it contained invalid fields",
                    self::MALFORMED_NOTIFICATION_CODE
                );

            case self::AUTHENTICATION_ERROR_CODE:
                throw new DispatchMessageException(
                    "There was an error authenticating the sender account.",
                    self::AUTHENTICATION_ERROR_CODE
                );

            default:
                throw new RuntimeException(
                    "Unknown error occurred while sending notification."
                );
        }
    }
753397
public function assertResponseStatusCodeEquals($inExpected, Response $inResponse, $message = '') {
        \PHPUnit_Framework_Assert::assertEquals($inExpected, $inResponse->getStatusCode(), $message);
    }
1075409
public function send(MessageContract $message)
    {
        $this->callSendingListener($message);

        $swiftMessage = $this->getSwiftMessage($message);

        $failedRecipients = [];

        $result = $this->newResult();

        try {
            $this->swiftMailer->send($swiftMessage, $failedRecipients);

            $result->increment();
            $result->addFailedRecipient($failedRecipients);

            $this->callSentListener($message);
        } catch (Exception $e) {
            $result->addFailedRecipient($this->guessRecipient($message), $e);
        }

        return $result;
    }
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);
	}
927542
public static function codeResponse($code,$message)
    {
        $code = intval($code);

        foreach(self::$results as $v) {
            if ($v['message'] == $message && $v['code'] == $code)
                return $v;
        }

        return null;
    }