/** * 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; }
/** * Reads the array in the next value. * * @param bool $returnObject Whether to return AMQPArray instance instead of plain array * @return array|PhpAmqpLib_Wire_AMQPArray */ public function read_array($returnObject = false) { $this->bitcount = $this->bits = 0; // Determine array length and its end position $arrayLength = $this->read_php_int(); $endOffset = $this->offset + $arrayLength; $result = $returnObject ? new PhpAmqpLib_Wire_AMQPArray() : array(); // Read values until we reach the end of the array while ($this->offset < $endOffset) { $fieldType = PhpAmqpLib_Wire_AMQPAbstractCollection::getDataTypeForSymbol($this->rawread(1)); $fieldValue = $this->read_value($fieldType, $returnObject); $returnObject ? $result->push($fieldValue, $fieldType) : ($result[] = $fieldValue); } return $result; }