aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/lib/Grpc/AbstractCall.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/php/lib/Grpc/AbstractCall.php')
-rw-r--r--src/php/lib/Grpc/AbstractCall.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/php/lib/Grpc/AbstractCall.php b/src/php/lib/Grpc/AbstractCall.php
index c58ee56742..e24be3fc76 100644
--- a/src/php/lib/Grpc/AbstractCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -121,6 +121,23 @@ abstract class AbstractCall
}
/**
+ * 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.
*
* @param string $value The binary value to deserialize
@@ -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);
}