Beispiel #1
0
 /**
  * @param integer $version_major
  * @param integer $version_minor
  * @param mixed $server_properties
  * @param string $mechanisms
  * @param string $locales
  * @return array
  */
 public function connectionStart($version_major = 0, $version_minor = 9, $server_properties, $mechanisms = 'PLAIN', $locales = 'en_US')
 {
     $writer = new AMQPWriter();
     $writer->write_octet($version_major);
     $writer->write_octet($version_minor);
     $writer->write_table(empty($server_properties) ? array() : $server_properties);
     $writer->write_longstr($mechanisms);
     $writer->write_longstr($locales);
     return array(10, 10, $writer);
 }
 /**
  * Returns a new AMQPWriter or mutates the provided $pkt
  *
  * @param $channel
  * @param $method_sig
  * @param string $args
  * @param AMQPWriter $pkt
  * @return null|AMQPWriter
  */
 protected function prepare_channel_method_frame($channel, $method_sig, $args = '', $pkt = null)
 {
     if ($args instanceof AMQPWriter) {
         $args = $args->getvalue();
     }
     if (empty($pkt)) {
         $pkt = new AMQPWriter();
     }
     $pkt->write_octet(1);
     $pkt->write_short($channel);
     $pkt->write_long(mb_strlen($args, 'ASCII') + 4);
     // 4 = length of class_id and method_id
     // in payload
     $pkt->write_short($method_sig[0]);
     // class_id
     $pkt->write_short($method_sig[1]);
     // method_id
     $pkt->write($args);
     $pkt->write_octet(0xce);
     $this->debug->debug_method_signature1($method_sig);
     return $pkt;
 }
Beispiel #3
0
 /**
  * Sends a heartbeat message
  */
 protected function write_heartbeat()
 {
     $pkt = new AMQPWriter();
     $pkt->write_octet(8);
     $pkt->write_short(0);
     $pkt->write_long(0);
     $pkt->write_octet(0xce);
     $this->write($pkt->getvalue());
 }
 /**
  * returns a new AMQPWriter or mutates the provided $pkt
  */
 protected function prepare_channel_method_frame($channel, $method_sig, $args = "", $pkt = null)
 {
     if ($args instanceof AMQPWriter) {
         $args = $args->getvalue();
     }
     if (empty($pkt)) {
         $pkt = new AMQPWriter();
     }
     $pkt->write_octet(1);
     $pkt->write_short($channel);
     $pkt->write_long(mb_strlen($args, 'ASCII') + 4);
     // 4 = length of class_id and method_id
     // in payload
     $pkt->write_short($method_sig[0]);
     // class_id
     $pkt->write_short($method_sig[1]);
     // method_id
     $pkt->write($args);
     $pkt->write_octet(0xce);
     if ($this->debug) {
         $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS;
         MiscHelper::debug_msg("< " . MiscHelper::methodSig($method_sig) . ": " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
     }
     return $pkt;
 }
Beispiel #5
0
 public function testTable($table, $integer_op, $string_op)
 {
     $args = new AMQPWriter();
     $args->write_table($table);
     $args->write_octet($integer_op);
     $args->write_octet($string_op);
     return array(120, 30, $args);
 }
 /**
  * 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)
 {
     $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;
 }
Beispiel #7
0
 /**
  * @param mixed $table
  * @param mixed $integer_op
  * @param mixed $string_op
  * @return array
  */
 public function testTable($table, $integer_op, $string_op)
 {
     $writer = new AMQPWriter();
     $writer->write_table(empty($table) ? array() : $table);
     $writer->write_octet($integer_op);
     $writer->write_octet($string_op);
     return array(120, 30, $writer);
 }
 protected function send_channel_method_frame($channel, $method_sig, $args = "")
 {
     if ($args instanceof AMQPWriter) {
         $args = $args->getvalue();
     }
     $pkt = new AMQPWriter();
     $pkt->write_octet(1);
     $pkt->write_short($channel);
     $pkt->write_long(strlen($args) + 4);
     // 4 = length of class_id and method_id
     // in payload
     $pkt->write_short($method_sig[0]);
     // class_id
     $pkt->write_short($method_sig[1]);
     // method_id
     $pkt->write($args);
     $pkt->write_octet(0xce);
     $pkt = $pkt->getvalue();
     $this->write($pkt);
     if ($this->debug) {
         MiscHelper::debug_msg("< " . MiscHelper::methodSig($method_sig) . ": " . AbstractChannel::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
     }
 }
 /**
  * Write PHP array, as table. Input array format: keys are strings,
  * values are (type,value) tuples.
  */
 public function write_table($d)
 {
     $table_data = new AMQPWriter();
     foreach ($d as $k => $va) {
         list($ftype, $v) = $va;
         $table_data->write_shortstr($k);
         if ($ftype == 'S') {
             $table_data->write('S');
             $table_data->write_longstr($v);
         } elseif ($ftype == 'I') {
             $table_data->write('I');
             $table_data->write_signed_long($v);
         } elseif ($ftype == 'D') {
             // 'D' type values are passed AMQPDecimal instances.
             $table_data->write('D');
             $table_data->write_octet($v->e);
             $table_data->write_signed_long($v->n);
         } elseif ($ftype == 'T') {
             $table_data->write('T');
             $table_data->write_timestamp($v);
         } elseif ($ftype == 'F') {
             $table_data->write('F');
             $table_data->write_table($v);
         } elseif ($ftype == 'A') {
             $table_data->write('A');
             $table_data->write_array($v);
         } elseif ($ftype == 't') {
             $table_data->write('t');
             $table_data->write_octet($v ? 1 : 0);
         } else {
             throw new AMQPInvalidArgumentException(sprintf("Invalid type '%s'", $ftype));
         }
     }
     $table_data = $table_data->getvalue();
     $this->write_long(strlen($table_data));
     $this->write($table_data);
     return $this;
 }