Esempio n. 1
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 serializeProperties()
 {
     if ($this->properties == []) {
         return "";
         // optimization for empty properties
     } else {
         $shift = 15;
         $flag_bits = 0;
         $flags = array();
         $raw_bytes = new AMQPBufferWriter();
         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 AMQPBufferWriter();
         foreach ($flags as $flag_bits) {
             $result->write_short($flag_bits);
         }
         $result->write($raw_bytes->getvalue());
         return $result->getvalue();
     }
 }
 /**
  * Write PHP array, as table. Input array format: keys are strings,
  * values are (type,value) tuples.
  *
  * @param AMQPTable|array $d Instance of AMQPTable or PHP array WITH format hints (unlike write_array())
  * @return self
  * @throws \DataProcessors\AMQP\Exception\AMQPInvalidArgumentException
  */
 public function write_table($d)
 {
     $typeIsSym = !$d instanceof AMQPTable;
     //purely for back-compat purposes
     $table_data = new AMQPBufferWriter();
     foreach ($d as $k => $va) {
         list($ftype, $v) = $va;
         $table_data->write_shortstr($k);
         $table_data->write_value($typeIsSym ? AMQPAbstractCollection::getDataTypeForSymbol($ftype) : $ftype, $v);
     }
     $table_data = $table_data->getvalue();
     $this->write_long(strlen($table_data));
     $this->write($table_data);
     return $this;
 }