php: clean up api around flags

pull/3181/head
Stanley Cheung 10 years ago
parent 3ab8e79b01
commit 5331776c17
  1. 16
      src/php/lib/Grpc/AbstractCall.php
  2. 7
      src/php/lib/Grpc/BidiStreamingCall.php
  3. 7
      src/php/lib/Grpc/ClientStreamingCall.php
  4. 7
      src/php/lib/Grpc/ServerStreamingCall.php
  5. 7
      src/php/lib/Grpc/UnaryCall.php
  6. 12
      src/php/tests/generated_code/AbstractGeneratedCodeTest.php

@ -92,20 +92,4 @@ abstract class AbstractCall {
}
return call_user_func($this->deserialize, $value);
}
/**
* Get the list of Grpc Write Flags
* @param array $options an array of options
* @return The list of Grpc Write Flags contained in the input
*/
protected static function getGrpcWriteFlags($options) {
$grpc_write_flags = [];
foreach ([WRITE_BUFFER_HINT,
WRITE_NO_COMPRESS] as $flag) {
if (in_array($flag, $options)) {
$grpc_write_flags[] = $flag;
}
}
return $grpc_write_flags;
}
}

@ -66,12 +66,13 @@ class BidiStreamingCall extends AbstractCall {
* Write a single message to the server. This cannot be called after
* writesDone is called.
* @param ByteBuffer $data The data to write
* @param array $options an array of options
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
public function write($data, $options = array()) {
$message_array = ['message' => $data->serialize()];
if ($grpc_write_flags = self::getGrpcWriteFlags($options)) {
$message_array['flags'] = $grpc_write_flags;
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([OP_SEND_MESSAGE => $message_array]);
}

@ -50,12 +50,13 @@ class ClientStreamingCall extends AbstractCall {
* 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
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
public function write($data, $options = array()) {
$message_array = ['message' => $data->serialize()];
if ($grpc_write_flags = self::getGrpcWriteFlags($options)) {
$message_array['flags'] = $grpc_write_flags;
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$this->call->startBatch([OP_SEND_MESSAGE => $message_array]);
}

@ -42,12 +42,13 @@ class ServerStreamingCall extends AbstractCall {
* Start the call
* @param $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
public function start($data, $metadata = array(), $options = array()) {
$message_array = ['message' => $data->serialize()];
if ($grpc_write_flags = self::getGrpcWriteFlags($options)) {
$message_array['flags'] = $grpc_write_flags;
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$event = $this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,

@ -42,12 +42,13 @@ class UnaryCall extends AbstractCall {
* Start the call
* @param $data The data to send
* @param array $metadata Metadata to send with the call, if applicable
* @param array $options an array of options
* @param array $options an array of options, possible keys:
* 'flags' => a number
*/
public function start($data, $metadata = array(), $options = array()) {
$message_array = ['message' => $data->serialize()];
if ($grpc_write_flags = self::getGrpcWriteFlags($options)) {
$message_array['flags'] = $grpc_write_flags;
if (isset($options['flags'])) {
$message_array['flags'] = $options['flags'];
}
$event = $this->call->startBatch([
OP_SEND_INITIAL_METADATA => $metadata,

@ -51,6 +51,18 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(is_string(self::$client->getTarget()));
}
public function testWriteFlags() {
$div_arg = new math\DivArgs();
$div_arg->setDividend(7);
$div_arg->setDivisor(4);
$call = self::$client->Div($div_arg, array(), array('flags' => Grpc\WRITE_NO_COMPRESS));
$this->assertTrue(is_string($call->getPeer()));
list($response, $status) = $call->wait();
$this->assertSame(1, $response->getQuotient());
$this->assertSame(3, $response->getRemainder());
$this->assertSame(\Grpc\STATUS_OK, $status->code);
}
public function testSimpleRequest() {
$div_arg = new math\DivArgs();
$div_arg->setDividend(7);

Loading…
Cancel
Save