Exemplo n.º 1
0
 public function testWriteArray()
 {
     $this->_writer->write_array(array('rabbit@localhost', 'hare@localhost', 42, true));
     $out = $this->_writer->getvalue();
     $this->assertEquals(51, mb_strlen($out, 'ASCII'));
     $expected = "/Srabbit@localhostShare@localhostI*t";
     $this->assertEquals($expected, $out);
 }
Exemplo n.º 2
0
 public function testArrayWriteReadCollection()
 {
     $w = new AMQPWriter();
     $w->write_array(new AMQPArray(array(12345, -12345, 3000000000, -3000000000, 9.2233720368548, (double) 9.2233720368548E+18, true, false, array(1, 2, 3, 'foo', array('bar' => 'baz'), array('boo', false, 5), true), array(), array('foo' => 'bar', 'baz' => 'boo', 'bool' => true, 'tbl' => array('bar' => 'baz'), 'arr' => array('boo', false, 5)), array(1 => 5, 3 => 'foo', 786 => 674), array(1, array(2, array(3, array(4)))), array('i' => 1, 'n' => array('i' => 2, 'n' => array('i' => 3, 'n' => array('i' => 4)))))));
     $r = new AMQPReader($w->getvalue());
     //type casting - thanks to ancient phpunit on travis
     $this->assertEquals(array(12345, -12345, (string) 3000000000, (string) -3000000000, (string) (double) 9.2233720368548, (string) (double) 9.2233720368548E+18, true, false, array(1, 2, 3, 'foo', array('bar' => 'baz'), array('boo', false, 5), true), array(), array('foo' => 'bar', 'baz' => 'boo', 'bool' => true, 'tbl' => array('bar' => 'baz'), 'arr' => array('boo', false, 5)), array(1 => 5, 3 => 'foo', 786 => 674), array(1, array(2, array(3, array(4)))), array('i' => 1, 'n' => array('i' => 2, 'n' => array('i' => 3, 'n' => array('i' => 4))))), $r->read_array(true)->getNativeData());
 }
Exemplo n.º 3
0
 /**
  * Write PHP array, as table. Input array format: keys are strings,
  * values are (type,value) tuples.
  */
 public function write_table($d)
 {
     $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);
         } elseif ($ftype == 'I') {
             $table_data->write('I');
             $table_data->write_signed_long($v);
         } elseif ($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);
         } 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);
         } elseif ($ftype == 't') {
             $table_data->write('t');
             $table_data->write_octet($v ? 1 : 0);
         } else {
             throw new AMQPInvalidArgumentException(sprintf("Invalid type '%s'", $ftype));
         }
     }
     $table_data = $table_data->getvalue();
     $this->write_long(strlen($table_data));
     $this->write($table_data);
     return $this;
 }