public function readByType(array $type, $isCollectionElement = false)
{
if ($this->data === null) {
return null;
}
switch ($type['type']) {
case DataTypeEnum::ASCII:
case DataTypeEnum::VARCHAR:
case DataTypeEnum::TEXT:
return $isCollectionElement ? $this->readString() : $this->data;
case DataTypeEnum::BIGINT:
case DataTypeEnum::COUNTER:
return $this->readBigInt($isCollectionElement);
case DataTypeEnum::VARINT:
return $this->readVarint($isCollectionElement);
case DataTypeEnum::CUSTOM:
case DataTypeEnum::BLOB:
return $this->readBytes($isCollectionElement);
case DataTypeEnum::BOOLEAN:
return $this->readBoolean();
case DataTypeEnum::DECIMAL:
return $this->readDecimal($isCollectionElement);
case DataTypeEnum::DOUBLE:
return $this->readDouble($isCollectionElement);
case DataTypeEnum::FLOAT:
return $this->readFloat($isCollectionElement);
case DataTypeEnum::INT:
return $this->readInt($isCollectionElement);
case DataTypeEnum::TIMESTAMP:
return $this->readTimestamp();
case DataTypeEnum::UUID:
return $this->readUuid($isCollectionElement);
case DataTypeEnum::TIMEUUID:
return $this->readUuid($isCollectionElement);
case DataTypeEnum::INET:
return $this->readInet($isCollectionElement);
case DataTypeEnum::COLLECTION_LIST:
case DataTypeEnum::COLLECTION_SET:
return $this->readList($type['value']);
case DataTypeEnum::COLLECTION_MAP:
return $this->readMap($type['key'], $type['value']);
}
trigger_error('Unknown type ' . var_export($type, true));
return null;
}
public function getData() { switch ($this->type) { case OpcodeEnum::ERROR: return $this->getErrorData(); case OpcodeEnum::READY: /** * Indicates that the server is ready to process queries. This message will be * sent by the server either after a STARTUP message if no authentication is * required, or after a successful CREDENTIALS message. */ return null; case OpcodeEnum::AUTHENTICATE: return unpack('n', $this->binary)[1]; case OpcodeEnum::SUPPORTED: /** * TODO Check it! * Indicates which startup options are supported by the server. This message * comes as a response to an OPTIONS message. * * 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 $this->dataStream->readByType(['type' => DataTypeEnum::COLLECTION_MAP]); case OpcodeEnum::RESULT: return $this->getResultData(); case OpcodeEnum::EVENT: // TODO return ''; default: throw new ResponseException('Unknown response'); } }