Skip to content

Commit

Permalink
support Register Request and Supported Response
Browse files Browse the repository at this point in the history
  • Loading branch information
shen2 committed Aug 31, 2014
1 parent 708a1eb commit b673aac
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
14 changes: 13 additions & 1 deletion Cassandra/Request/Register.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php
namespace Cassandra\Request;
use Cassandra\Protocol\Frame;
use Cassandra\Protocol\DataType;

class Register extends Request{

protected $opcode = Frame::OPCODE_REGISTER;

/**
*
* @var array
*/
protected $_events;

/**
* REGISTER
*
Expand All @@ -23,6 +30,11 @@ class Register extends Request{
*
* @param array $events
*/
public function __construct($body) {
public function __construct(array $events) {
$this->_events = $events;
}

public function getBody(){
return DataType::getList($this->_events, array('type' => DataType::TEXT));
}
}
16 changes: 16 additions & 0 deletions Cassandra/Response/DataStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ public function readDecimal() {
$len = strlen($value);
return substr($value, 0, $len - $scale) . '.' . substr($value, $len - $scale);
}

public function readStringMultimap(){
$map = array();
$count = $this->readShort();
for($i = 0; $i < $count; $i++){
$key = $this->readString();

$listLength = $this->readShort();
$list = array();
for($j = 0; $j < $listLength; $j++)
$list[] = $this->readString();

$map[$key] = $list;
}
return $map;
}

/**
* @param array $type
Expand Down
12 changes: 6 additions & 6 deletions Cassandra/Response/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Result extends DataStream{
* @param array $type
* @return mixed
*/
public function readByTypeFromStream(array $type){
protected function _readByTypeFromStream(array $type){
$length = unpack('N', substr($this->data, $this->offset, 4))[1];
$this->offset += 4;

Expand Down Expand Up @@ -108,7 +108,7 @@ public function getData() {
$row = new \ArrayObject();

foreach ($columns as $column)
$row[$column['name']] = self::readByTypeFromStream($column['type']);
$row[$column['name']] = $this->_readByTypeFromStream($column['type']);

$rows[$i] = $row;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ public function fetchAll($rowClass = 'ArrayObject'){
$row = new $rowClass();

foreach ($columns as $column)
$row[$column['name']] = self::readByTypeFromStream($column['type']);
$row[$column['name']] = $this->_readByTypeFromStream($column['type']);

$rows[$i] = $row;
}
Expand All @@ -251,7 +251,7 @@ public function fetchCol($index = 0){

for($i = 0; $i < $rowCount; ++$i){
for($j = 0; $j < $columnCount; ++$j){
$value = self::readByTypeFromStream($columns[$j]['type']);
$value = $this->_readByTypeFromStream($columns[$j]['type']);

if ($j == $index)
$array[$i] = $row;
Expand Down Expand Up @@ -279,7 +279,7 @@ public function fetchRow($rowClass = 'ArrayObject'){

$row = new $rowClass();
foreach ($columns as $column)
$row[$column['name']] = self::readByTypeFromStream($column['type']);
$row[$column['name']] = $this->_readByTypeFromStream($column['type']);

return $row;
}
Expand All @@ -301,7 +301,7 @@ public function fetchOne(){
return null;

foreach ($columns as $column)
return self::readByTypeFromStream($column['type']);
return $this->_readByTypeFromStream($column['type']);

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Cassandra/Response/Supported.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function getData(){
* The body of a SUPPORTED message is a [string multimap]. This multimap gives
* for each of the supported STARTUP options, the list of supported values.
*/
return parent::readByType(['type' => DataType::COLLECTION_MAP]);
return $this->readStringMultimap();
}
}

0 comments on commit b673aac

Please sign in to comment.