Пример #1
0
 /**
  * Waits for a frame from the server.
  *
  * @return array
  * @throws \DataProcessors\AMQP\Exception\AMQPRuntimeException
  */
 protected function waitForAnyFrame()
 {
     // frame_type + channel_id + size
     $data = (yield $this->readExactly(AMQPBufferReader::OCTET + AMQPBufferReader::SHORT + AMQPBufferReader::LONG));
     $this->bufferReader->reuse($data);
     $frame_type = $this->bufferReader->read_octet();
     $channel = $this->bufferReader->read_short();
     $size = $this->bufferReader->read_long();
     // payload + ch
     $data = (yield $this->readExactly(AMQPBufferReader::OCTET + (int) $size));
     $this->bufferReader->reuse($data);
     $payload = $this->bufferReader->read($size);
     $ch = $this->bufferReader->read_octet();
     if ($ch != Constants091::FRAME_END) {
         throw new Exception\AMQPRuntimeException(sprintf('Framing error, unexpected byte: %x', $ch));
     }
     (yield [$frame_type, $channel, $payload]);
 }
Пример #2
0
 public function testTableWriteReadCollection()
 {
     $w = new AMQPBufferWriter();
     $w->write_table(new AMQPTable(array('long' => 12345, 'long_neg' => -12345, 'longlong' => 3000000000, 'longlong_neg' => -3000000000, 'float_low' => 9.2233720368548, 'float_high' => (double) 9.2233720368548E+18, 'bool_true' => true, 'bool_false' => false, 'array' => array(1, 2, 3, 'foo', array('bar' => 'baz'), array('boo', false, 5), true), 'array_empty' => array(), 'table' => array('foo' => 'bar', 'baz' => 'boo', 'bool' => true, 'tbl' => array('bar' => 'baz'), 'arr' => array('boo', false, 5)), 'table_num' => array(1 => 5, 3 => 'foo', 786 => 674), 'array_nested' => array(1, array(2, array(3, array(4)))), 'table_nested' => array('i' => 1, 'n' => array('i' => 2, 'n' => array('i' => 3, 'n' => array('i' => 4)))))));
     $r = new AMQPBufferReader($w->getvalue());
     //type casting - thanks to ancient phpunit on travis
     $this->assertEquals(array('long' => 12345, 'long_neg' => -12345, 'longlong' => (string) 3000000000, 'longlong_neg' => (string) -3000000000, 'float_low' => (string) (double) 9.2233720368548, 'float_high' => (string) (double) 9.2233720368548E+18, 'bool_true' => true, 'bool_false' => false, 'array' => array(1, 2, 3, 'foo', array('bar' => 'baz'), array('boo', false, 5), true), 'array_empty' => array(), 'table' => array('foo' => 'bar', 'baz' => 'boo', 'bool' => true, 'tbl' => array('bar' => 'baz'), 'arr' => array('boo', false, 5)), 'table_num' => array(1 => 5, 3 => 'foo', 786 => 674), 'array_nested' => array(1, array(2, array(3, array(4)))), 'table_nested' => array('i' => 1, 'n' => array('i' => 2, 'n' => array('i' => 3, 'n' => array('i' => 4))))), $r->read_table(true)->getNativeData());
 }