PHP Proto3: new serialization/deserialization for messages
diff --git a/src/php/lib/Grpc/AbstractCall.php b/src/php/lib/Grpc/AbstractCall.php
index c58ee56..e24be3f 100644
--- a/src/php/lib/Grpc/AbstractCall.php
+++ b/src/php/lib/Grpc/AbstractCall.php
@@ -121,6 +121,23 @@
     }
 
     /**
+     * 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 @@
             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);
     }