diff options
author | Sree Kuchibhotla <sreek@google.com> | 2016-10-17 14:15:50 -0700 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2016-10-17 14:15:50 -0700 |
commit | 34ad82d6f683b06ecb3844769ef53784d8cba30b (patch) | |
tree | 27551d64348144de399c7f874adfedbf919458d3 /src/php/lib/Grpc/AbstractCall.php | |
parent | 923d641c27f0ebcceb67a28fd17168ac34e7bf5e (diff) | |
parent | 872559593329f1a6903d0b41f669eb4ba719dbe8 (diff) |
Merge branch 'master' into new_scenario
Diffstat (limited to 'src/php/lib/Grpc/AbstractCall.php')
-rw-r--r-- | src/php/lib/Grpc/AbstractCall.php | 26 |
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); } |