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) {
         $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS;
         MiscHelper::debug_msg("< " . MiscHelper::methodSig($method_sig) . ": " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
     }
 }
示例#2
0
 /**
  * Write PHP array, as table. Input array format: keys are strings,
  * values are (type,value) tuples.
  */
 public function write_table($d)
 {
     $this->flushbits();
     $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);
         } else {
             throw new \InvalidArgumentException(sprintf("Invalid type '%s'", $ftype));
         }
     }
     $table_data = $table_data->getvalue();
     $this->write_long(strlen($table_data));
     $this->write($table_data);
     return $this;
 }
示例#3
0
 /**
  * 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();
 }