/** * 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(); }
/** * 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; }
public function testInteger($integer_1, $integer_2, $integer_3, $integer_4, $operation) { $args = new PhpAmqpLib_Wire_AMQPWriter(); $args->write_octet($integer_1); $args->write_short($integer_2); $args->write_long($integer_3); $args->write_longlong($integer_4); $args->write_octet($operation); return array(120, 10, $args); }
/** * @return array */ public function basicGet($ticket = 0, $queue = '', $no_ack = false) { $args = new PhpAmqpLib_Wire_AMQPWriter(); $args->write_short($ticket); $args->write_shortstr($queue); $args->write_bits(array($no_ack)); return array(60, 70, $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; }