/**
  * Create ColumnSpec from binary data.
  *
  * @param DataStream $data
  * @param string $keyspace
  * @param string $tablename
  */
 public function __construct(DataStream $data, $keyspace = NULL, $tablename = NULL)
 {
     if (is_null($keyspace)) {
         $this->keyspace = $data->readString();
         $this->tablename = $data->readString();
     } else {
         $this->keyspace = $keyspace;
         $this->tablename = $tablename;
     }
     $this->name = $data->readString();
     $this->type = new TypeSpec($data);
 }
Esempio n. 2
0
 /**
  * Construct new TypeSpec from binary data.
  *
  * @param DataStream $data
  */
 public function __construct(DataStream $data)
 {
     $this->type = $data->readShort();
     switch ($this->type) {
         case self::CUSTOM:
             $this->customTypename = $data->readString();
             break;
         case self::COLLECTION_LIST:
         case self::COLLECTION_SET:
             $this->valueType = new TypeSpec($data);
             break;
         case self::COLLECTION_MAP:
             $this->keyType = new TypeSpec($data);
             $this->valueType = new TypeSpec($data);
             break;
     }
 }
Esempio n. 3
0
 /**
  * Get current row.
  *
  * @see Iterator::current()
  */
 public function current()
 {
     if (!isset($this->rows[$this->current])) {
         throw new OutOfRangeException('Invalid index');
     }
     $row = $this->rows[$this->current];
     $object = new stdClass();
     for ($i = 0; $i < $this->columnCount; ++$i) {
         try {
             $data = new DataStream($this->rows[$this->current][$i]);
             $row[$i] = $data->readByType($this->columns[$i]->getType());
         } catch (Exception $e) {
             $row[$i] = null;
         }
     }
     return $row;
 }
Esempio n. 4
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);
 }