PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / grpc / grpc / src / lib / UnaryCall.php

UnaryCall.php in Media Cloud Sync 1.4.2, at includes/sdk/google/grpc/grpc/src/lib/UnaryCall.php

78 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 *
5 * Copyright 2015 gRPC authors.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */
20 namespace Dudlewebs\WPMCS\GCP\Grpc;
21
22 /**
23 * Represents an active call that sends a single message and then gets a
24 * single response.
25 *
26 * @template T of \Google\Protobuf\Internal\Message
27 */
28 class UnaryCall extends AbstractCall
29 {
30 /**
31 * Start the call.
32 *
33 * @param mixed $data The data to send
34 * @param array $metadata Metadata to send with the call, if applicable
35 * (optional)
36 * @param array $options An array of options, possible keys:
37 * 'flags' => a number (optional)
38 */
39 public function start($data, array $metadata = [], array $options = [])
40 {
41 $message_array = ['message' => $this->_serializeMessage($data)];
42 if (isset($options['flags'])) {
43 $message_array['flags'] = $options['flags'];
44 }
45 $this->call->startBatch([OP_SEND_INITIAL_METADATA => $metadata, OP_SEND_MESSAGE => $message_array, OP_SEND_CLOSE_FROM_CLIENT => \true]);
46 }
47 /**
48 * Wait for the server to respond with data and a status.
49 *
50 * @return array{0: T|null, 1: \stdClass} [response data, status]
51 */
52 public function wait()
53 {
54 $batch = [OP_RECV_MESSAGE => \true, OP_RECV_STATUS_ON_CLIENT => \true];
55 if ($this->metadata === null) {
56 $batch[OP_RECV_INITIAL_METADATA] = \true;
57 }
58 $event = $this->call->startBatch($batch);
59 if ($this->metadata === null) {
60 $this->metadata = $event->metadata;
61 }
62 $status = $event->status;
63 $this->trailing_metadata = $status->metadata;
64 return [$this->_deserializeResponse($event->message), $status];
65 }
66 /**
67 * @return mixed The metadata sent by the server
68 */
69 public function getMetadata()
70 {
71 if ($this->metadata === null) {
72 $event = $this->call->startBatch([OP_RECV_INITIAL_METADATA => \true]);
73 $this->metadata = $event->metadata;
74 }
75 return $this->metadata;
76 }
77 }
78