function longlongWriteAndRead($v)
 {
     $w = new AMQPWriter();
     $w->write_longlong($v);
     $r = new AMQPReader($w->getvalue());
     $this->assertEqual($r->read_longlong(), $v);
 }
Exemple #2
0
 /**
  * negotiate connection tuning parameters
  */
 protected function x_tune_ok($channel_max, $frame_max, $heartbeat)
 {
     $args = new AMQPWriter();
     $args->write_short($channel_max);
     $args->write_long($frame_max);
     $args->write_short($heartbeat);
     $this->send_method_frame(array(10, 31), $args);
     $this->wait_tune_ok = False;
 }
Exemple #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 (array_key_exists($key, $this->properties)) {
             $val = $this->properties[$key];
         } else {
             $val = NULL;
         }
         if ($val != NULL) {
             if ($shift == 0) {
                 array_push($flags, $flag_bits);
                 $flag_bits = 0;
                 $shift = 15;
             }
             $flag_bits |= 1 << $shift;
             if ($proptype != "bit") {
                 call_user_func(array($raw_bytes, "write_" . $proptype), $val);
             }
         }
         $shift -= 1;
     }
     array_push($flags, $flag_bits);
     $result = new AMQPWriter();
     foreach ($flags as $flag_bits) {
         $result->write_short($flag_bits);
     }
     $result->write($raw_bytes->getvalue());
     return $result->getvalue();
 }
Exemple #4
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);
         } else {
             if ($ftype == 'I') {
                 $table_data->write('I');
                 $table_data->write_signed_long($v);
             } else {
                 if ($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);
                 } else {
                     if ($ftype == 'T') {
                         $table_data->write('T');
                         $table_data->write_timestamp($v);
                     } else {
                         if ($ftype == 'F') {
                             $table_data->write('F');
                             $table_data->write_table($v);
                         }
                     }
                 }
             }
         }
     }
     $table_data = $table_data->getvalue();
     $this->write_long(strlen($table_data));
     $this->write($table_data);
     return $this;
 }
Exemple #5
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();
 }
Exemple #6
0
 public function basicReject($delivery_tag, $requeue)
 {
     $args = new AMQPWriter();
     $args->write_longlong($delivery_tag)->write_bit($requeue);
     return $args;
 }