/** * Returns a new AMQPWriter or mutates the provided $pkt * * @param string $channel * @param int $class_id * @param int $weight * @param int $body_size * @param string $packed_properties * @param string $body * @param AMQPWriter $pkt * @return AMQPWriter */ public function prepare_content($channel, $class_id, $weight, $body_size, $packed_properties, $body, $pkt = null) { if (empty($pkt)) { $pkt = new AMQPWriter(); } // Content already prepared ? $key_cache = sprintf('%s|%s|%s|%s', $channel, $packed_properties, $class_id, $weight); if (!isset($this->prepare_content_cache[$key_cache])) { $w = new AMQPWriter(); $w->write_octet(2); $w->write_short($channel); $w->write_long(mb_strlen($packed_properties, 'ASCII') + 12); $w->write_short($class_id); $w->write_short($weight); $this->prepare_content_cache[$key_cache] = $w->getvalue(); if (count($this->prepare_content_cache) > $this->prepare_content_cache_max_size) { reset($this->prepare_content_cache); $old_key = key($this->prepare_content_cache); unset($this->prepare_content_cache[$old_key]); } } $pkt->write($this->prepare_content_cache[$key_cache]); $pkt->write_longlong($body_size); $pkt->write($packed_properties); $pkt->write_octet(0xce); // memory efficiency: walk the string instead of biting // it. good for very large packets (close in size to // memory_limit setting) $position = 0; $bodyLength = mb_strlen($body, 'ASCII'); while ($position < $bodyLength) { $payload = mb_substr($body, $position, $this->frame_max - 8, 'ASCII'); $position += $this->frame_max - 8; $pkt->write_octet(3); $pkt->write_short($channel); $pkt->write_long(mb_strlen($payload, 'ASCII')); $pkt->write($payload); $pkt->write_octet(0xce); } return $pkt; }
/** * returns a new AMQPWriter or mutates the provided $pkt * * @param string $channel * @param int $class_id * @param int $weight * @param int $body_size * @param string $packed_properties * @param string $body * @param AMQPWriter $pkt * @return AMQPWriter */ public function prepare_content($channel, $class_id, $weight, $body_size, $packed_properties, $body, $pkt = null) { if (empty($pkt)) { $pkt = new AMQPWriter(); } // Content already prepared ? $key_cache = "{$channel}|{$packed_properties}|{$class_id}|{$weight}"; if (!isset($this->prepare_content_cache[$key_cache])) { $w = new AMQPWriter(); $w->write_octet(2); $w->write_short($channel); $w->write_long(mb_strlen($packed_properties, 'ASCII') + 12); $w->write_short($class_id); $w->write_short($weight); $this->prepare_content_cache[$key_cache] = $w->getvalue(); if (count($this->prepare_content_cache) > $this->prepare_content_cache_max_size) { reset($this->prepare_content_cache); $old_key = key($this->prepare_content_cache); unset($this->prepare_content_cache[$old_key]); } } $pkt->write($this->prepare_content_cache[$key_cache]); $pkt->write_longlong($body_size); $pkt->write($packed_properties); $pkt->write_octet(0xce); while ($body) { $bodyStart = $this->frame_max - 8; $payload = mb_substr($body, 0, $bodyStart, 'ASCII'); $body = mb_substr($body, $bodyStart, mb_strlen($body, 'ASCII') - $bodyStart, 'ASCII'); $pkt->write_octet(3); $pkt->write_short($channel); $pkt->write_long(mb_strlen($payload, 'ASCII')); $pkt->write($payload); $pkt->write_octet(0xce); } return $pkt; }
/** * @param integer $delivery_tag * @param boolean $multiple * @param boolean $requeue * @return array */ public function basicNack($delivery_tag = 0, $multiple = false, $requeue = true) { $writer = new AMQPWriter(); $writer->write_longlong($delivery_tag); $writer->write_bits(array($multiple, $requeue)); return array(60, 120, $writer); }
public function testInteger($integer_1, $integer_2, $integer_3, $integer_4, $operation) { $args = new AMQPWriter(); $args->write_octet($integer_1); $args->write_short($integer_2); $args->write_long($integer_3); $args->write_longlong($integer_4); $args->write_octet($operation); return array(120, 10, $args); }
public function send_content($channel, $class_id, $weight, $body_size, $packed_properties, $body) { $pkt = new AMQPWriter(); $pkt->write_octet(2); $pkt->write_short($channel); $pkt->write_long(strlen($packed_properties) + 12); $pkt->write_short($class_id); $pkt->write_short($weight); $pkt->write_longlong($body_size); $pkt->write($packed_properties); $pkt->write_octet(0xce); $pkt = $pkt->getvalue(); $this->write($pkt); while ($body) { $payload = substr($body, 0, $this->frame_max - 8); $body = substr($body, $this->frame_max - 8); $pkt = new AMQPWriter(); $pkt->write_octet(3); $pkt->write_short($channel); $pkt->write_long(strlen($payload)); $pkt->write($payload); $pkt->write_octet(0xce); $pkt = $pkt->getvalue(); $this->write($pkt); } }
/** * returns a new AMQPWriter or mutates the provided $pkt */ public function prepare_content($channel, $class_id, $weight, $body_size, $packed_properties, $body, $pkt = null) { if (empty($pkt)) { $pkt = new AMQPWriter(); } $pkt->write_octet(2); $pkt->write_short($channel); $pkt->write_long(strlen($packed_properties) + 12); $pkt->write_short($class_id); $pkt->write_short($weight); $pkt->write_longlong($body_size); $pkt->write($packed_properties); $pkt->write_octet(0xce); while ($body) { $payload = substr($body, 0, $this->frame_max - 8); $body = substr($body, $this->frame_max - 8); $pkt->write_octet(3); $pkt->write_short($channel); $pkt->write_long(strlen($payload)); $pkt->write($payload); $pkt->write_octet(0xce); } return $pkt; }
public function basicNack($delivery_tag = 0, $multiple = false, $requeue = true) { $args = new AMQPWriter(); $args->write_longlong($delivery_tag); $args->write_bit($multiple); $args->write_bit($requeue); return array(60, 120, $args); }
public function basicReject($delivery_tag, $requeue) { $args = new AMQPWriter(); $args->write_longlong($delivery_tag)->write_bit($requeue); return $args; }