/** * Given the raw bytes containing the property-flags and * property-list from a content-frame-header, parse and insert * into a dictionary stored in this object as an attribute named * 'properties'. */ public function load_properties($raw_bytes) { $r = new AMQPReader($raw_bytes); // Read 16-bit shorts until we get one with a low bit set to zero $flags = array(); while (true) { $flag_bits = $r->read_short(); $flags[] = $flag_bits; if (($flag_bits & 1) == 0) { break; } } $shift = 0; $d = array(); foreach ($this->prop_types as $key => $proptype) { if ($shift == 0) { if (!$flags) { break; } $flag_bits = array_shift($flags); $shift = 15; } if ($flag_bits & 1 << $shift) { $d[$key] = $r->{'read_' . $proptype}(); } $shift -= 1; } $this->properties = $d; }
/** * @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; }
/** * @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(); //hack to avoid creating new instances of AMQPReader; $this->msg_property_reader->reuse(mb_substr($payload, 12, mb_strlen($payload, 'ASCII') - 12, 'ASCII')); return $this->createMessage($this->msg_property_reader, $this->wait_content_reader); }
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; }
/** * @return 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 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); $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; throw new AMQPRuntimeException(sprintf('Expecting Content body, received frame type %s (%s)', $frame_type, $PROTOCOL_CONSTANTS_CLASS::$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) { MiscHelper::debug_msg('Ignoring body decoding exception: ' . $e->getMessage()); } } } return $msg; }
/** * Proposes connection tuning parameters * * @param AMQPReader $args */ protected function connection_tune($args) { $v = $args->read_short(); if ($v) { $this->channel_max = $v; } $v = $args->read_long(); if ($v) { $this->frame_max = $v; } // use server proposed value if not set if ($this->heartbeat === null) { $this->heartbeat = $args->read_short(); } $this->x_tune_ok($this->channel_max, $this->frame_max, $this->heartbeat); }
/** * @param AMQPReader $reader * @return array */ public static function accessRequestOk(AMQPReader $reader) { $response = array(); $response[] = $reader->read_short(); return $response; }
/** * Returns a failed message * * @param AMQPReader $args * @param AMQPMessage $msg */ protected function basic_return($args, $msg) { $reply_code = $args->read_short(); $reply_text = $args->read_shortstr(); $exchange = $args->read_shortstr(); $routing_key = $args->read_shortstr(); if (null !== $this->basic_return_callback) { call_user_func_array($this->basic_return_callback, array($reply_code, $reply_text, $exchange, $routing_key, $msg)); } elseif ($this->debug) { MiscHelper::debug_msg('Skipping unhandled basic_return message'); } }
/** * @param AMQPReader $args * @return array */ public static function accessRequestOk($args) { $ret = array(); $ret[] = $args->read_short(); return $ret; }
/** * propose connection tuning parameters * * @param AMQPReader $args */ protected function connection_tune($args) { $v = $args->read_short(); if ($v) { $this->channel_max = $v; } $v = $args->read_long(); if ($v) { $this->frame_max = $v; } $this->heartbeat = $args->read_short(); $this->x_tune_ok($this->channel_max, $this->frame_max, 0); }
/** * Returns a failed message * * @param AMQPReader $reader * @param AMQPMessage $message * @return null */ protected function basic_return($reader, $message) { $callback = $this->basic_return_callback; if (!is_callable($callback)) { $this->debug->debug_msg('Skipping unhandled basic_return message'); return null; } $reply_code = $reader->read_short(); $reply_text = $reader->read_shortstr(); $exchange = $reader->read_shortstr(); $routing_key = $reader->read_shortstr(); call_user_func_array($callback, array($reply_code, $reply_text, $exchange, $routing_key, $message)); }