/** * 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 PhpAmqpLib_Wire_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 PhpAmqpLib_Wire_AMQPWriter(); 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 PhpAmqpLib_Exception_AMQPInvalidArgumentException */ public function write_table($d) { $typeIsSym = !$d instanceof AMQPTable; //purely for back-compat purposes $table_data = new PhpAmqpLib_Wire_AMQPWriter(); foreach ($d as $k => $va) { list($ftype, $v) = $va; $table_data->write_shortstr($k); $table_data->write_value($typeIsSym ? PhpAmqpLib_Wire_AMQPAbstractCollection::getDataTypeForSymbol($ftype) : $ftype, $v); } $table_data = $table_data->getvalue(); $this->write_long(mb_strlen($table_data, 'ASCII')); $this->write($table_data); return $this; }
/** * 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 PhpAmqpLib_Wire_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 PhpAmqpLib_Wire_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 PhpAmqpLib_Wire_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; }
/** * 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 PhpAmqpLib_Wire_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 PhpAmqpLib_Wire_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; }
public function testTable($table, $integer_op, $string_op) { $args = new PhpAmqpLib_Wire_AMQPWriter(); $args->write_table($table); $args->write_octet($integer_op); $args->write_octet($string_op); return array(120, 30, $args); }
/** * @return array */ public function confirmSelect($nowait = false) { $args = new PhpAmqpLib_Wire_AMQPWriter(); $args->write_bits(array($nowait)); return array(85, 10, $args); }
/** * Sends a heartbeat message */ protected function write_heartbeat() { $pkt = new PhpAmqpLib_Wire_AMQPWriter(); $pkt->write_octet(8); $pkt->write_short(0); $pkt->write_long(0); $pkt->write_octet(0xce); $this->write($pkt->getvalue()); }
/** * Negotiates connection tuning parameters * * @param $channel_max * @param $frame_max * @param $heartbeat */ protected function x_tune_ok($channel_max, $frame_max, $heartbeat) { $args = new PhpAmqpLib_Wire_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; }
/** * Publish batch * * @return void */ public function publish_batch() { if (empty($this->batch_messages)) { return; } /** @var PhpAmqpLib_Wire_AMQPWriter $pkt */ $pkt = new PhpAmqpLib_Wire_AMQPWriter(); /** @var PhpAmqpLib_Message_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(); }