|
|
|
@ -120,6 +120,23 @@ abstract class AbstractCall |
|
|
|
|
$this->call->cancel(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Serialize a message to the protobuf binary format |
|
|
|
|
* |
|
|
|
|
* @param mixed $data The Protobuf message |
|
|
|
|
* |
|
|
|
|
* @return string The protobuf binary format |
|
|
|
|
*/ |
|
|
|
|
protected function serializeMessage($data) { |
|
|
|
|
// Proto3 implementation |
|
|
|
|
if (method_exists($data, 'encode')) { |
|
|
|
|
return $data->encode(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Protobuf-PHP implementation |
|
|
|
|
return $data->serialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Deserialize a response value to an object. |
|
|
|
|
* |
|
|
|
@ -133,6 +150,15 @@ abstract class AbstractCall |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Proto3 implementation |
|
|
|
|
if (is_array($this->deserialize)) { |
|
|
|
|
list($className, $deserializeFunc) = $this->deserialize; |
|
|
|
|
$obj = new $className(); |
|
|
|
|
$obj->$deserializeFunc($value); |
|
|
|
|
return $obj; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Protobuf-PHP implementation |
|
|
|
|
return call_user_func($this->deserialize, $value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|