예제 #1
0
 /**
  * Create Rows object from binary data.
  *
  * @param DataStream $data
  */
 public function __construct(DataStream $data)
 {
     $flags = $data->readInt();
     $this->columnCount = $data->readInt();
     if ($flags & 0x1) {
         // Keyspace and tablename are specified globally.
         $keyspace = $data->readString();
         $tablename = $data->readString();
     } else {
         // Keyspace and tablename are specified per column.
         $keyspace = null;
         $tablename = null;
     }
     for ($i = 0; $i < $this->columnCount; ++$i) {
         $this->columns[] = new ColumnSpec($data, $keyspace, $tablename);
     }
     $this->rowCount = $data->readInt();
     for ($i = 0; $i < $this->rowCount; ++$i) {
         $row = array();
         for ($j = 0; $j < $this->columnCount; ++$j) {
             try {
                 $row[] = $data->readBytes();
             } catch (Exception $e) {
                 $row[] = null;
             }
         }
         $this->rows[] = $row;
     }
 }
예제 #2
0
 /**
  * Read error frame.
  *
  * @param DataStream $data
  * @return Exception
  */
 public function readError(DataStream $data)
 {
     $code = $data->readInt();
     $messages = array(0x0 => 'Server error', 0xa => 'Protocol error', 0x100 => 'Bad credentials', 0x1000 => 'Unavailable', 0x1001 => 'Overloaded', 0x1002 => 'Is bootstrapping', 0x1003 => 'Truncate error', 0x1100 => 'Write timeout', 0x1200 => 'Read timeout', 0x2000 => true, 0x2100 => 'Unauthorized', 0x2200 => true, 0x2300 => 'Config error', 0x2400 => 'Already exists', 0x2500 => 'Unprepared');
     if (isset($messages[$code])) {
         $message = $messages[$code];
         if ($message === true) {
             $message = $data->readString();
         }
     } else {
         $message = 'Unknown error';
     }
     return new Exception($message, $code);
 }