Skip to content

Commit 8bf5439

Browse files
committed
Clients/Gibson: added GB_ENC_NUMBER support.
1 parent 09b550b commit 8bf5439

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

PHPDaemon/Clients/Gibson/Connection.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Connection extends ClientConnection {
2727
const STATE_PACKET_HDR = 0x01;
2828
const STATE_PACKET_DATA = 0x02;
2929

30+
const GB_ENC_PLAIN = 0x00; // Raw string data follows.
31+
const GB_ENC_LZF = 0x01; // Compressed data, this is a reserved value not used for replies.
32+
const GB_ENC_NUMBER = 0x02; // Packed long number follows, four bytes for 32bit architectures, eight bytes for 64bit.
33+
34+
3035

3136
/**
3237
* Default low mark. Minimum number of bytes in buffer.
@@ -154,7 +159,13 @@ protected function onRead() {
154159
goto cursorCall;
155160
}
156161
$this->drain($o);
157-
$this->result[$key] = $this->read($valLen);
162+
if ($encoding === static::GB_ENC_NUMBER) {
163+
$this->result[$key] = $valLen === 8
164+
? Binary::getQword($this->read($valLen), true)
165+
: Binary::getDword($this->read($valLen), true);
166+
} else {
167+
$this->result[$key] = $this->read($valLen);
168+
}
158169
if (++$this->readedNum >= $this->totalNum) {
159170
$this->isFinal = true;
160171
$this->executeCb();
@@ -171,6 +182,11 @@ protected function onRead() {
171182
$this->setWatermark($this->responseLength);
172183
return;
173184
}
185+
if ($this->encoding === static::GB_ENC_NUMBER) {
186+
$this->result = $this->responseLength === 8
187+
? Binary::getQword($this->result, true)
188+
: Binary::getDword($this->result, true);
189+
}
174190
$this->isFinal = true;
175191
$this->totalNum = 1;
176192
$this->readedNum = 1;

PHPDaemon/Examples/ExampleGibson.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function init(){
6060
}
6161

6262
$job('testquery', function ($jobname, $job) { // registering job named 'testquery'
63-
$this->appInstance->gibson->mget('key', function($conn) use ($job, $jobname){
63+
$this->appInstance->gibson->inc('counter', function($conn) use ($job, $jobname){
6464
if ($conn->isFinal()) {
6565
$job->setResult($jobname, $conn->result);
6666
}

0 commit comments

Comments
 (0)