示例#1
0
 /**
  * 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;
 }
 /**
  * serialize the 'properties' attribute (a dictionary) into the
  * raw bytes making up a set of property flags and a property
  * list, suitable for putting into a content frame header.
  */
 public function serialize_properties()
 {
     $shift = 15;
     $flag_bits = 0;
     $flags = array();
     $raw_bytes = new AMQPWriter();
     foreach ($this->prop_types as $key => $proptype) {
         if (isset($this->properties[$key])) {
             $val = $this->properties[$key];
         } else {
             $val = null;
         }
         if ($val != null) {
             if ($shift == 0) {
                 $flags[] = $flag_bits;
                 $flag_bits = 0;
                 $shift = 15;
             }
             $flag_bits |= 1 << $shift;
             if ($proptype != "bit") {
                 $raw_bytes->{'write_' . $proptype}($val);
             }
         }
         $shift -= 1;
     }
     $flags[] = $flag_bits;
     $result = new AMQPWriter();
     foreach ($flags as $flag_bits) {
         $result->write_short($flag_bits);
     }
     $result->write($raw_bytes->getvalue());
     return $result->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;
 }
示例#4
0
 /**
  * Publish batch
  *
  * @return void
  */
 public function publish_batch()
 {
     if (empty($this->batch_messages)) {
         return;
     }
     /** @var AMQPWriter $pkt */
     $pkt = new AMQPWriter();
     /** @var AMQPMessage $msg */
     foreach ($this->batch_messages as $m) {
         $msg = $m[0];
         $exchange = isset($m[1]) ? $m[1] : '';
         $routing_key = isset($m[2]) ? $m[2] : '';
         $mandatory = isset($m[3]) ? $m[3] : false;
         $immediate = isset($m[4]) ? $m[4] : false;
         $ticket = isset($m[5]) ? $m[5] : null;
         $pkt->write($this->pre_publish($exchange, $routing_key, $mandatory, $immediate, $ticket));
         $this->connection->prepare_content($this->channel_id, 60, 0, mb_strlen($msg->body, 'ASCII'), $msg->serialize_properties(), $msg->body, $pkt);
         if ($this->next_delivery_tag > 0) {
             $this->published_messages[$this->next_delivery_tag] = $msg;
             $this->next_delivery_tag = bcadd($this->next_delivery_tag, '1', 0);
         }
     }
     //call write here
     $this->connection->write($pkt->getvalue());
     $this->batch_messages = array();
 }
示例#5
0
 /**
  * Serializes the 'properties' attribute (a dictionary) into the
  * raw bytes making up a set of property flags and a property
  * list, suitable for putting into a content frame header.
  *
  * @return string
  * @todo Inject the AMQPWriter to make the method easier to test
  */
 public function serialize_properties()
 {
     if (!empty($this->serialized_properties)) {
         return $this->serialized_properties;
     }
     $shift = 15;
     $flag_bits = 0;
     $flags = array();
     $raw_bytes = new AMQPWriter();
     foreach ($this->prop_types as $key => $prototype) {
         $val = isset($this->properties[$key]) ? $this->properties[$key] : null;
         // Very important: PHP type eval is weak, use the === to test the
         // value content. Zero or false value should not be removed
         if ($val === null) {
             $shift -= 1;
             continue;
         }
         if ($shift === 0) {
             $flags[] = $flag_bits;
             $flag_bits = 0;
             $shift = 15;
         }
         $flag_bits |= 1 << $shift;
         if ($prototype != 'bit') {
             $raw_bytes->{'write_' . $prototype}($val);
         }
         $shift -= 1;
     }
     $flags[] = $flag_bits;
     $result = new AMQPWriter();
     foreach ($flags as $flag_bits) {
         $result->write_short($flag_bits);
     }
     $result->write($raw_bytes->getvalue());
     $this->serialized_properties = $result->getvalue();
     return $this->serialized_properties;
 }
 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)]);
     }
 }
 /**
  * serialize the 'properties' attribute (a dictionary) into the
  * raw bytes making up a set of property flags and a property
  * list, suitable for putting into a content frame header.
  */
 public function serialize_properties()
 {
     if (!empty($this->serialized_properties)) {
         return $this->serialized_properties;
     }
     $shift = 15;
     $flag_bits = 0;
     $flags = array();
     $raw_bytes = new AMQPWriter();
     foreach ($this->prop_types as $key => $prototype) {
         $val = isset($this->properties[$key]) ? $this->properties[$key] : null;
         if ($val === null) {
             $shift -= 1;
             continue;
         }
         if ($shift === 0) {
             $flags[] = $flag_bits;
             $flag_bits = 0;
             $shift = 15;
         }
         $flag_bits |= 1 << $shift;
         if ($prototype != 'bit') {
             $raw_bytes->{'write_' . $prototype}($val);
         }
         $shift -= 1;
     }
     $flags[] = $flag_bits;
     $result = new AMQPWriter();
     foreach ($flags as $flag_bits) {
         $result->write_short($flag_bits);
     }
     $result->write($raw_bytes->getvalue());
     $this->serialized_properties = $result->getvalue();
     return $this->serialized_properties;
 }
示例#8
0
 /**
  * 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;
 }