public function wait_content() { $frm = $this->next_frame(); $frame_type = $frm[0]; $payload = $frm[1]; if ($frame_type != 2) { throw new PhpAmqpLib_Exception_AMQPRuntimeException("Expecting Content header"); } $payload_reader = new PhpAmqpLib_Wire_AMQPReader(substr($payload, 0, 12)); $class_id = $payload_reader->read_short(); $weight = $payload_reader->read_short(); $body_size = $payload_reader->read_longlong(); $msg = new PhpAmqpLib_Message_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) { $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS; throw new PhpAmqpLib_Exception_AMQPRuntimeException("Expecting Content body, received frame type {$frame_type} (" . $PROTOCOL_CONSTANTS_CLASS::$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) { PhpAmqpLib_Helper_MiscHelper::debug_msg("Ignoring body decoding exception: " . $e->getMessage()); } } } return $msg; }
/** * @return PhpAmqpLib_Message_AMQPMessage * @throws _PhpAmqpLib_Exception_AMQPRuntimeException */ public function wait_content() { $frm = $this->next_frame(); $frame_type = $frm[0]; $payload = $frm[1]; if ($frame_type != 2) { throw new PhpAmqpLib_Exception_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 PhpAmqpLib_Message_AMQPMessage(); $msg->load_properties($this->msg_property_reader); $msg->body_size = $body_size; $body_parts = array(); $body_received = 0; while (bccomp($body_size, $body_received, 0) == 1) { $frm = $this->next_frame(); $frame_type = $frm[0]; $payload = $frm[1]; if ($frame_type != 3) { $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS; $FRAME_TYPES = self::getStaticProperty($PROTOCOL_CONSTANTS_CLASS, 'FRAME_TYPES'); throw new PhpAmqpLib_Exception_AMQPRuntimeException(sprintf('Expecting Content body, received frame type %s (%s)', $frame_type, $FRAME_TYPES[$frame_type])); } $body_received = bcadd($body_received, mb_strlen($payload, 'ASCII'), 0); if (!is_null($this->body_size_max) && $body_received > $this->body_size_max) { $msg->is_truncated = true; continue; } $body_parts[] = $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) { PhpAmqpLib_Helper_MiscHelper::debug_msg('Ignoring body decoding exception: ' . $e->getMessage()); } } } return $msg; }