aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/lib/Grpc/ClientStreamingCall.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/php/lib/Grpc/ClientStreamingCall.php')
-rw-r--r--src/php/lib/Grpc/ClientStreamingCall.php75
1 files changed, 50 insertions, 25 deletions
diff --git a/src/php/lib/Grpc/ClientStreamingCall.php b/src/php/lib/Grpc/ClientStreamingCall.php
index 61439d3f47..500cfe0d7a 100644
--- a/src/php/lib/Grpc/ClientStreamingCall.php
+++ b/src/php/lib/Grpc/ClientStreamingCall.php
@@ -31,36 +31,61 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
+
namespace Grpc;
/**
* Represents an active call that sends a stream of messages and then gets a
* single response.
*/
-class ClientStreamingCall extends AbstractCall {
- /**
- * Start the call.
- * @param Traversable $arg_iter The iterator of arguments to send
- * @param array $metadata Metadata to send with the call, if applicable
- */
- public function start($arg_iter, $metadata = array()) {
- $event = $this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata]);
- foreach($arg_iter as $arg) {
- $this->call->startBatch([OP_SEND_MESSAGE => $arg->serialize()]);
+class ClientStreamingCall extends AbstractCall
+{
+ /**
+ * Start the call.
+ *
+ * @param array $metadata Metadata to send with the call, if applicable
+ */
+ public function start($metadata = [])
+ {
+ $this->call->startBatch([
+ OP_SEND_INITIAL_METADATA => $metadata,
+ ]);
+ }
+
+ /**
+ * Write a single message to the server. This cannot be called after
+ * wait is called.
+ *
+ * @param ByteBuffer $data The data to write
+ * @param array $options an array of options, possible keys:
+ * 'flags' => a number
+ */
+ public function write($data, $options = [])
+ {
+ $message_array = ['message' => $data->serialize()];
+ if (isset($options['flags'])) {
+ $message_array['flags'] = $options['flags'];
+ }
+ $this->call->startBatch([
+ OP_SEND_MESSAGE => $message_array,
+ ]);
}
- $this->call->startBatch([OP_SEND_CLOSE_FROM_CLIENT => true]);
- }
- /**
- * Wait for the server to respond with data and a status
- * @return [response data, status]
- */
- public function wait() {
- $event = $this->call->startBatch([
- OP_RECV_INITIAL_METADATA => true,
- OP_RECV_MESSAGE => true,
- OP_RECV_STATUS_ON_CLIENT => true]);
- $this->metadata = $event->metadata;
- return array($this->deserializeResponse($event->message), $event->status);
- }
-} \ No newline at end of file
+ /**
+ * Wait for the server to respond with data and a status.
+ *
+ * @return [response data, status]
+ */
+ public function wait()
+ {
+ $event = $this->call->startBatch([
+ OP_SEND_CLOSE_FROM_CLIENT => true,
+ OP_RECV_INITIAL_METADATA => true,
+ OP_RECV_MESSAGE => true,
+ OP_RECV_STATUS_ON_CLIENT => true,
+ ]);
+ $this->metadata = $event->metadata;
+
+ return [$this->deserializeResponse($event->message), $event->status];
+ }
+}