/**
  * @dataProvider propertiesDataProvider
  */
 public function testSerializeProperties(array $expected, array $properties)
 {
     /** @var AMQPReader $reader */
     $reader = new AMQPReader(null);
     /** @var AMQPMessage $message */
     $message = new AMQPMessage('', $properties);
     /** @var string $encodedData */
     $encodedData = $message->serialize_properties();
     // Bypasses the network part and injects the encoded data into the reader
     $reader->reuse($encodedData);
     // Injects the reader into the message
     $message->load_properties($reader);
     $this->assertEquals($expected, $message->get_properties());
 }
Пример #2
0
 public function wait_content()
 {
     $frm = $this->next_frame();
     $frame_type = $frm[0];
     $payload = $frm[1];
     if ($frame_type != 2) {
         throw new AMQPRuntimeException("Expecting Content header");
     }
     $payload_reader = new AMQPReader(substr($payload, 0, 12));
     $class_id = $payload_reader->read_short();
     $weight = $payload_reader->read_short();
     $body_size = $payload_reader->read_longlong();
     $msg = new AMQPMessage();
     $msg->load_properties(substr($payload, 12));
     $body_parts = array();
     $body_received = 0;
     while (bccomp($body_size, $body_received) == 1) {
         $frm = $this->next_frame();
         $frame_type = $frm[0];
         $payload = $frm[1];
         if ($frame_type != 3) {
             throw new AMQPRuntimeException("Expecting Content body, received frame type {$frame_type} (" . self::$FRAME_TYPES[$frame_type] . ")");
         }
         $body_parts[] = $payload;
         $body_received = bcadd($body_received, strlen($payload));
     }
     $msg->body = implode("", $body_parts);
     if ($this->auto_decode && isset($msg->content_encoding)) {
         try {
             $msg->body = $msg->body->decode($msg->content_encoding);
         } catch (\Exception $e) {
             if ($this->debug) {
                 MiscHelper::debug_msg("Ignoring body decoding exception: " . $e->getMessage());
             }
         }
     }
     return $msg;
 }
Пример #3
0
 /**
  * @param AMQPReader $propertyReader
  * @param AMQPReader $contentReader
  * @return \PhpAmqpLib\Message\AMQPMessage
  */
 protected function createMessage($propertyReader, $contentReader)
 {
     $bodyChunks = array();
     $bodyReceivedBytes = 0;
     $message = new AMQPMessage();
     $message->load_properties($propertyReader)->setBodySize($contentReader->read_longlong());
     while (bccomp($message->getBodySize(), $bodyReceivedBytes, 0) == 1) {
         list($frame_type, $payload) = $this->next_frame();
         $this->validate_body_frame($frame_type);
         $bodyReceivedBytes = bcadd($bodyReceivedBytes, mb_strlen($payload, 'ASCII'), 0);
         if (is_int($this->maxBodySize) && $bodyReceivedBytes > $this->maxBodySize) {
             $message->setIsTruncated(true);
             continue;
         }
         $bodyChunks[] = $payload;
     }
     $message->setBody(implode('', $bodyChunks));
     $messageEncoding = $message->getContentEncoding();
     if ($this->auto_decode && !empty($messageEncoding)) {
         try {
             // Where does the decode() method come from if body is a string?
             $decodedBody = $message->getBody()->decode($messageEncoding);
             $message->setBody($decodedBody);
         } catch (\Exception $e) {
             $this->debug->debug_msg('Ignoring body decoding exception: ' . $e->getMessage());
         }
     }
     return $message;
 }
 public function wait_content()
 {
     $frm = $this->next_frame();
     $frame_type = $frm[0];
     $payload = $frm[1];
     if ($frame_type != 2) {
         throw new AMQPRuntimeException("Expecting Content header");
     }
     $this->wait_content_reader->reuse(mb_substr($payload, 0, 12, 'ASCII'));
     // $payload_reader = new AMQPReader(substr($payload,0,12));
     $class_id = $this->wait_content_reader->read_short();
     $weight = $this->wait_content_reader->read_short();
     $body_size = $this->wait_content_reader->read_longlong();
     //hack to avoid creating new instances of AMQPReader;
     $this->msg_property_reader->reuse(mb_substr($payload, 12, mb_strlen($payload, 'ASCII') - 12, 'ASCII'));
     $msg = new AMQPMessage();
     $msg->load_properties($this->msg_property_reader);
     $body_parts = [];
     $body_received = 0;
     while (bccomp($body_size, $body_received) == 1) {
         $frm = $this->next_frame();
         $frame_type = $frm[0];
         $payload = $frm[1];
         if ($frame_type != 3) {
             $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS;
             throw new AMQPRuntimeException("Expecting Content body, received frame type {$frame_type} (" . $PROTOCOL_CONSTANTS_CLASS::$FRAME_TYPES[$frame_type] . ")");
         }
         $body_parts[] = $payload;
         $body_received = bcadd($body_received, mb_strlen($payload, 'ASCII'));
     }
     $msg->body = implode("", $body_parts);
     if ($this->auto_decode && isset($msg->content_encoding)) {
         try {
             $msg->body = $msg->body->decode($msg->content_encoding);
         } catch (\Exception $e) {
             if ($this->debug) {
                 MiscHelper::debug_msg("Ignoring body decoding exception: " . $e->getMessage());
             }
         }
     }
     return $msg;
 }
Пример #5
0
 /**
  * @return AMQPMessage
  * @throws \PhpAmqpLib\Exception\AMQPRuntimeException
  */
 public function wait_content()
 {
     list($frame_type, $payload) = $this->next_frame();
     $this->validate_header_frame($frame_type);
     $this->wait_content_reader->reuse(mb_substr($payload, 0, 12, 'ASCII'));
     // $payload_reader = new AMQPReader(substr($payload,0,12));
     $class_id = $this->wait_content_reader->read_short();
     $weight = $this->wait_content_reader->read_short();
     $body_size = $this->wait_content_reader->read_longlong();
     //hack to avoid creating new instances of AMQPReader;
     $this->msg_property_reader->reuse(mb_substr($payload, 12, mb_strlen($payload, 'ASCII') - 12, 'ASCII'));
     $msg = new AMQPMessage();
     $msg->load_properties($this->msg_property_reader);
     $msg->body_size = $body_size;
     list($msg_body, $is_truncated) = $this->build_msg_body($body_size);
     $msg->body = $msg_body;
     $msg->is_truncated = $is_truncated;
     if ($this->auto_decode && isset($msg->content_encoding)) {
         try {
             $msg->body = $msg->body->decode($msg->content_encoding);
         } catch (\Exception $e) {
             $this->debug->debug_msg('Ignoring body decoding exception: ' . $e->getMessage());
         }
     }
     return $msg;
 }
Пример #6
0
 /**
  * @param AMQPReader $propertyReader
  * @param AMQPReader $contentReader
  * @return \PhpAmqpLib\Message\AMQPMessage
  */
 protected function createMessage($propertyReader, $contentReader)
 {
     $bodyChunks = array();
     $bodyReceivedBytes = 0;
     $message = new AMQPMessage();
     $message->load_properties($propertyReader)->setBodySize($contentReader->read_longlong());
     while (bccomp($message->getBodySize(), $bodyReceivedBytes, 0) == 1) {
         list($frame_type, $payload) = $this->next_frame();
         $this->validate_body_frame($frame_type);
         $bodyReceivedBytes = bcadd($bodyReceivedBytes, mb_strlen($payload, 'ASCII'), 0);
         if (is_int($this->maxBodySize) && $bodyReceivedBytes > $this->maxBodySize) {
             $message->setIsTruncated(true);
             continue;
         }
         $bodyChunks[] = $payload;
     }
     $message->setBody(implode('', $bodyChunks));
     return $message;
 }