/** * Read an AMQP table, and return as a PHP array. keys are strings, * values are (type,value) tuples. * * @return array * @throws \Exception */ public function readTable() { $this->_bitcount = $this->_bits = 0; $tlen = $this->readPhpInt(); if ($tlen < 0) { throw new \Exception('Table is longer than supported'); } $tableData = new Reader($this->_rawread($tlen)); $result = array(); while ($tableData->tell() < $tlen) { $name = $tableData->readShortstr(); $ftype = $tableData->_rawread(1); if ($ftype == 'S') { $val = $tableData->readLongstr(); } else { if ($ftype == 'I') { $val = $tableData->_readSignedLong(); } else { if ($ftype == 'D') { $e = $tableData->readOctet(); $n = $tableData->_readSignedLong(); $val = new Decimal($n, $e); } else { if ($ftype == 'T') { $val = $tableData->readTimestamp(); } else { if ($ftype == 'F') { $val = $tableData->readTable(); // recursion } else { error_log(sprintf('Usupported table field type %s', $ftype)); $val = null; } } } } } $result[$name] = array($ftype, $val); } return $result; }
/** * start connection negotiation */ protected function start(Reader $args) { $this->versionMajor = $args->readOctet(); $this->versionMinor = $args->readOctet(); $this->serverProperties = $args->readTable(); $this->mechanisms = explode(" ", $args->readLongstr()); $this->locales = explode(" ", $args->readLongstr()); if ($this->debug) { Helper::debugMsg(sprintf('Start from server, version: %d.%d, properties: %s, ' . 'mechanisms: %s, locales: %s', $this->versionMajor, $this->versionMinor, self::dumpTable($this->serverProperties), implode(', ', $this->mechanisms), implode(', ', $this->locales))); } }