diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/php/README.md | 3 | ||||
-rw-r--r-- | examples/php/greeter_client.php | 10 | ||||
-rwxr-xr-x | examples/php/greeter_proto_gen.sh | 17 | ||||
-rw-r--r-- | examples/php/helloworld.pb.php | 58 | ||||
-rw-r--r-- | examples/php/helloworld_grpc_pb.php | 49 | ||||
-rw-r--r-- | examples/php/route_guide/route_guide.pb.php | 209 | ||||
-rw-r--r-- | examples/php/route_guide/route_guide_client.php | 43 | ||||
-rw-r--r-- | examples/php/route_guide/route_guide_grpc_pb.php | 101 | ||||
-rwxr-xr-x | examples/php/route_guide/route_guide_proto_gen.sh | 16 | ||||
-rw-r--r-- | examples/python/helloworld/helloworld_pb2.py | 145 | ||||
-rw-r--r-- | examples/python/helloworld/helloworld_pb2_grpc.py | 3 | ||||
-rw-r--r-- | examples/python/route_guide/route_guide_pb2.py | 310 | ||||
-rw-r--r-- | examples/python/route_guide/route_guide_pb2_grpc.py | 3 |
13 files changed, 145 insertions, 822 deletions
diff --git a/examples/php/README.md b/examples/php/README.md index d30cbdafd0..49703ce172 100644 --- a/examples/php/README.md +++ b/examples/php/README.md @@ -41,10 +41,11 @@ TRY IT! $ node greeter_server.js ``` - - Run the client + - Generate proto files and run the client ``` $ cd examples/php + $ ./greeter_proto_gen.sh $ ./run_greeter_client.sh ``` diff --git a/examples/php/greeter_client.php b/examples/php/greeter_client.php index 981319a451..bb94a08527 100644 --- a/examples/php/greeter_client.php +++ b/examples/php/greeter_client.php @@ -17,12 +17,14 @@ * */ +// php:generate protoc --proto_path=./../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../bins/opt/grpc_php_plugin ./../protos/helloworld.proto + require dirname(__FILE__).'/vendor/autoload.php'; -// The following includes are needed when using protobuf 3.1.0 -// and will suppress warnings when using protobuf 3.2.0+ -@include_once dirname(__FILE__).'/helloworld.pb.php'; -@include_once dirname(__FILE__).'/helloworld_grpc_pb.php'; +@include_once dirname(__FILE__).'/Helloworld/GreeterClient.php'; +@include_once dirname(__FILE__).'/Helloworld/HelloReply.php'; +@include_once dirname(__FILE__).'/Helloworld/HelloRequest.php'; +@include_once dirname(__FILE__).'/GPBMetadata/Helloworld.php'; function greet($name) { diff --git a/examples/php/greeter_proto_gen.sh b/examples/php/greeter_proto_gen.sh new file mode 100755 index 0000000000..a0d7b29c86 --- /dev/null +++ b/examples/php/greeter_proto_gen.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright 2017 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +protoc --proto_path=./../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../bins/opt/grpc_php_plugin ./../protos/helloworld.proto + diff --git a/examples/php/helloworld.pb.php b/examples/php/helloworld.pb.php deleted file mode 100644 index 757a4a58f5..0000000000 --- a/examples/php/helloworld.pb.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: helloworld.proto - -namespace Helloworld; - -use Google\Protobuf\Internal\DescriptorPool; -use Google\Protobuf\Internal\GPBType; -use Google\Protobuf\Internal\RepeatedField; -use Google\Protobuf\Internal\GPBUtil; - -class HelloRequest extends \Google\Protobuf\Internal\Message -{ - private $name = ''; - - public function getName() - { - return $this->name; - } - - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - } - -} - -class HelloReply extends \Google\Protobuf\Internal\Message -{ - private $message = ''; - - public function getMessage() - { - return $this->message; - } - - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - } - -} - -$pool = DescriptorPool::getGeneratedPool(); - -$pool->internalAddGeneratedFile(hex2bin( - "0ae6010a1068656c6c6f776f726c642e70726f746f120a68656c6c6f776f" . - "726c64221c0a0c48656c6c6f52657175657374120c0a046e616d65180120" . - "012809221d0a0a48656c6c6f5265706c79120f0a076d6573736167651801" . - "2001280932490a0747726565746572123e0a0853617948656c6c6f12182e" . - "68656c6c6f776f726c642e48656c6c6f526571756573741a162e68656c6c" . - "6f776f726c642e48656c6c6f5265706c79220042360a1b696f2e67727063" . - "2e6578616d706c65732e68656c6c6f776f726c64420f48656c6c6f576f72" . - "6c6450726f746f5001a20203484c57620670726f746f33" -)); - diff --git a/examples/php/helloworld_grpc_pb.php b/examples/php/helloworld_grpc_pb.php deleted file mode 100644 index ba83ed2614..0000000000 --- a/examples/php/helloworld_grpc_pb.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -// GENERATED CODE -- DO NOT EDIT! - -// Original file comments: -// Copyright 2015 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -namespace Helloworld { - - // The greeting service definition. - class GreeterClient extends \Grpc\BaseStub { - - /** - * @param string $hostname hostname - * @param array $opts channel options - * @param Grpc\Channel $channel (optional) re-use channel object - */ - public function __construct($hostname, $opts, $channel = null) { - parent::__construct($hostname, $opts, $channel); - } - - /** - * Sends a greeting - * @param \Helloworld\HelloRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - */ - public function SayHello(\Helloworld\HelloRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/helloworld.Greeter/SayHello', - $argument, - ['\Helloworld\HelloReply', 'decode'], - $metadata, $options); - } - - } - -} diff --git a/examples/php/route_guide/route_guide.pb.php b/examples/php/route_guide/route_guide.pb.php deleted file mode 100644 index 78f3ea6e2a..0000000000 --- a/examples/php/route_guide/route_guide.pb.php +++ /dev/null @@ -1,209 +0,0 @@ -<?php -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: route_guide.proto - -namespace Routeguide; - -use Google\Protobuf\Internal\DescriptorPool; -use Google\Protobuf\Internal\GPBType; -use Google\Protobuf\Internal\RepeatedField; -use Google\Protobuf\Internal\GPBUtil; - -class Point extends \Google\Protobuf\Internal\Message -{ - private $latitude = 0; - private $longitude = 0; - - public function getLatitude() - { - return $this->latitude; - } - - public function setLatitude($var) - { - GPBUtil::checkInt32($var); - $this->latitude = $var; - } - - public function getLongitude() - { - return $this->longitude; - } - - public function setLongitude($var) - { - GPBUtil::checkInt32($var); - $this->longitude = $var; - } - -} - -class Rectangle extends \Google\Protobuf\Internal\Message -{ - private $lo = null; - private $hi = null; - - public function getLo() - { - return $this->lo; - } - - public function setLo(&$var) - { - GPBUtil::checkMessage($var, \Routeguide\Point::class); - $this->lo = $var; - } - - public function getHi() - { - return $this->hi; - } - - public function setHi(&$var) - { - GPBUtil::checkMessage($var, \Routeguide\Point::class); - $this->hi = $var; - } - -} - -class Feature extends \Google\Protobuf\Internal\Message -{ - private $name = ''; - private $location = null; - - public function getName() - { - return $this->name; - } - - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - } - - public function getLocation() - { - return $this->location; - } - - public function setLocation(&$var) - { - GPBUtil::checkMessage($var, \Routeguide\Point::class); - $this->location = $var; - } - -} - -class RouteNote extends \Google\Protobuf\Internal\Message -{ - private $location = null; - private $message = ''; - - public function getLocation() - { - return $this->location; - } - - public function setLocation(&$var) - { - GPBUtil::checkMessage($var, \Routeguide\Point::class); - $this->location = $var; - } - - public function getMessage() - { - return $this->message; - } - - public function setMessage($var) - { - GPBUtil::checkString($var, True); - $this->message = $var; - } - -} - -class RouteSummary extends \Google\Protobuf\Internal\Message -{ - private $point_count = 0; - private $feature_count = 0; - private $distance = 0; - private $elapsed_time = 0; - - public function getPointCount() - { - return $this->point_count; - } - - public function setPointCount($var) - { - GPBUtil::checkInt32($var); - $this->point_count = $var; - } - - public function getFeatureCount() - { - return $this->feature_count; - } - - public function setFeatureCount($var) - { - GPBUtil::checkInt32($var); - $this->feature_count = $var; - } - - public function getDistance() - { - return $this->distance; - } - - public function setDistance($var) - { - GPBUtil::checkInt32($var); - $this->distance = $var; - } - - public function getElapsedTime() - { - return $this->elapsed_time; - } - - public function setElapsedTime($var) - { - GPBUtil::checkInt32($var); - $this->elapsed_time = $var; - } - -} - -$pool = DescriptorPool::getGeneratedPool(); - -$pool->internalAddGeneratedFile(hex2bin( - "0ac5050a11726f7574655f67756964652e70726f746f120a726f75746567" . - "75696465222c0a05506f696e7412100a086c617469747564651801200128" . - "0512110a096c6f6e67697475646518022001280522490a0952656374616e" . - "676c65121d0a026c6f18012001280b32112e726f75746567756964652e50" . - "6f696e74121d0a02686918022001280b32112e726f75746567756964652e" . - "506f696e74223c0a0746656174757265120c0a046e616d65180120012809" . - "12230a086c6f636174696f6e18022001280b32112e726f75746567756964" . - "652e506f696e7422410a09526f7574654e6f746512230a086c6f63617469" . - "6f6e18012001280b32112e726f75746567756964652e506f696e74120f0a" . - "076d65737361676518022001280922620a0c526f75746553756d6d617279" . - "12130a0b706f696e745f636f756e7418012001280512150a0d6665617475" . - "72655f636f756e7418022001280512100a0864697374616e636518032001" . - "280512140a0c656c61707365645f74696d651804200128053285020a0a52" . - "6f757465477569646512360a0a4765744665617475726512112e726f7574" . - "6567756964652e506f696e741a132e726f75746567756964652e46656174" . - "7572652200123e0a0c4c697374466561747572657312152e726f75746567" . - "756964652e52656374616e676c651a132e726f75746567756964652e4665" . - "617475726522003001123e0a0b5265636f7264526f75746512112e726f75" . - "746567756964652e506f696e741a182e726f75746567756964652e526f75" . - "746553756d6d61727922002801123f0a09526f7574654368617412152e72" . - "6f75746567756964652e526f7574654e6f74651a152e726f757465677569" . - "64652e526f7574654e6f746522002801300142360a1b696f2e677270632e" . - "6578616d706c65732e726f7574656775696465420f526f75746547756964" . - "6550726f746f5001a20203525447620670726f746f33" -)); - diff --git a/examples/php/route_guide/route_guide_client.php b/examples/php/route_guide/route_guide_client.php index 8ac797722c..92b2bacecd 100644 --- a/examples/php/route_guide/route_guide_client.php +++ b/examples/php/route_guide/route_guide_client.php @@ -17,12 +17,9 @@ * */ -require dirname(__FILE__).'/../vendor/autoload.php'; +// php:generate protoc --proto_path=./../../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../../bins/opt/grpc_php_plugin ./../../protos/route_guide.proto -// The following includes are needed when using protobuf 3.1.0 -// and will suppress warnings when using protobuf 3.2.0+ -@include_once dirname(__FILE__).'/route_guide.pb.php'; -@include_once dirname(__FILE__).'/route_guide_grpc_pb.php'; +require dirname(__FILE__).'/../vendor/autoload.php'; define('COORD_FACTOR', 1e7); @@ -38,9 +35,12 @@ function printFeature($feature) } else { $name_str = "feature called $name"; } - echo sprintf("Found %s \n at %f, %f\n", $name_str, + echo sprintf( + "Found %s \n at %f, %f\n", + $name_str, $feature->getLocation()->getLatitude() / COORD_FACTOR, - $feature->getLocation()->getLongitude() / COORD_FACTOR); + $feature->getLocation()->getLongitude() / COORD_FACTOR + ); } /** @@ -122,19 +122,24 @@ function runRecordRoute() $feature_name = $db[$index]['name']; $point->setLatitude($lat); $point->setLongitude($long); - echo sprintf("Visiting point %f, %f,\n with feature name: %s\n", - $lat / COORD_FACTOR, $long / COORD_FACTOR, - $feature_name ? $feature_name : '<empty>'); + echo sprintf( + "Visiting point %f, %f,\n with feature name: %s\n", + $lat / COORD_FACTOR, + $long / COORD_FACTOR, + $feature_name ? $feature_name : '<empty>' + ); usleep(rand(300000, 800000)); $call->write($point); } list($route_summary, $status) = $call->wait(); - echo sprintf("Finished trip with %d points\nPassed %d features\n". + echo sprintf( + "Finished trip with %d points\nPassed %d features\n". "Travelled %d meters\nIt took %d seconds\n", $route_summary->getPointCount(), $route_summary->getFeatureCount(), $route_summary->getDistance(), - $route_summary->getElapsedTime()); + $route_summary->getElapsedTime() + ); } /** @@ -166,8 +171,12 @@ function runRouteChat() $route_note->setLocation($point); $route_note->setMessage($message = $n[2]); - echo sprintf("Sending message: '%s' at (%d, %d)\n", - $message, $lat, $long); + echo sprintf( + "Sending message: '%s' at (%d, %d)\n", + $message, + $lat, + $long + ); // send a bunch of messages to the server $call->write($route_note); } @@ -175,10 +184,12 @@ function runRouteChat() // read from the server until there's no more while ($route_note_reply = $call->read()) { - echo sprintf("Previous left message at (%d, %d): '%s'\n", + echo sprintf( + "Previous left message at (%d, %d): '%s'\n", $route_note_reply->getLocation()->getLatitude(), $route_note_reply->getLocation()->getLongitude(), - $route_note_reply->getMessage()); + $route_note_reply->getMessage() + ); } } diff --git a/examples/php/route_guide/route_guide_grpc_pb.php b/examples/php/route_guide/route_guide_grpc_pb.php deleted file mode 100644 index e7a9cd39cd..0000000000 --- a/examples/php/route_guide/route_guide_grpc_pb.php +++ /dev/null @@ -1,101 +0,0 @@ -<?php -// GENERATED CODE -- DO NOT EDIT! - -// Original file comments: -// Copyright 2015 gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -namespace Routeguide { - - // Interface exported by the server. - class RouteGuideClient extends \Grpc\BaseStub { - - /** - * @param string $hostname hostname - * @param array $opts channel options - * @param Grpc\Channel $channel (optional) re-use channel object - */ - public function __construct($hostname, $opts, $channel = null) { - parent::__construct($hostname, $opts, $channel); - } - - /** - * A simple RPC. - * - * Obtains the feature at a given position. - * - * A feature with an empty name is returned if there's no feature at the given - * position. - * @param \Routeguide\Point $argument input argument - * @param array $metadata metadata - * @param array $options call options - */ - public function GetFeature(\Routeguide\Point $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', - $argument, - ['\Routeguide\Feature', 'decode'], - $metadata, $options); - } - - /** - * A server-to-client streaming RPC. - * - * Obtains the Features available within the given Rectangle. Results are - * streamed rather than returned at once (e.g. in a response message with a - * repeated field), as the rectangle may cover a large area and contain a - * huge number of features. - * @param \Routeguide\Rectangle $argument input argument - * @param array $metadata metadata - * @param array $options call options - */ - public function ListFeatures(\Routeguide\Rectangle $argument, - $metadata = [], $options = []) { - return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', - $argument, - ['\Routeguide\Feature', 'decode'], - $metadata, $options); - } - - /** - * A client-to-server streaming RPC. - * - * Accepts a stream of Points on a route being traversed, returning a - * RouteSummary when traversal is completed. - * @param array $metadata metadata - * @param array $options call options - */ - public function RecordRoute($metadata = [], $options = []) { - return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', - ['\Routeguide\RouteSummary','decode'], - $metadata, $options); - } - - /** - * A Bidirectional streaming RPC. - * - * Accepts a stream of RouteNotes sent while a route is being traversed, - * while receiving other RouteNotes (e.g. from other users). - * @param array $metadata metadata - * @param array $options call options - */ - public function RouteChat($metadata = [], $options = []) { - return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', - ['\Routeguide\RouteNote','decode'], - $metadata, $options); - } - - } - -} diff --git a/examples/php/route_guide/route_guide_proto_gen.sh b/examples/php/route_guide/route_guide_proto_gen.sh new file mode 100755 index 0000000000..bfd7cdb725 --- /dev/null +++ b/examples/php/route_guide/route_guide_proto_gen.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2015 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +protoc --proto_path=./../../protos --php_out=./ --grpc_out=./ --plugin=protoc-gen-grpc=./../../../bins/opt/grpc_php_plugin ./../../protos/route_guide.proto diff --git a/examples/python/helloworld/helloworld_pb2.py b/examples/python/helloworld/helloworld_pb2.py index 6665b1f687..e18ab9acc7 100644 --- a/examples/python/helloworld/helloworld_pb2.py +++ b/examples/python/helloworld/helloworld_pb2.py @@ -21,7 +21,6 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_pb=_b('\n\x10helloworld.proto\x12\nhelloworld\"\x1c\n\x0cHelloRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\x1d\n\nHelloReply\x12\x0f\n\x07message\x18\x01 \x01(\t2I\n\x07Greeter\x12>\n\x08SayHello\x12\x18.helloworld.HelloRequest\x1a\x16.helloworld.HelloReply\"\x00\x42\x36\n\x1bio.grpc.examples.helloworldB\x0fHelloWorldProtoP\x01\xa2\x02\x03HLWb\x06proto3') ) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -89,6 +88,7 @@ _HELLOREPLY = _descriptor.Descriptor( DESCRIPTOR.message_types_by_name['HelloRequest'] = _HELLOREQUEST DESCRIPTOR.message_types_by_name['HelloReply'] = _HELLOREPLY +_sym_db.RegisterFileDescriptor(DESCRIPTOR) HelloRequest = _reflection.GeneratedProtocolMessageType('HelloRequest', (_message.Message,), dict( DESCRIPTOR = _HELLOREQUEST, @@ -107,123 +107,28 @@ _sym_db.RegisterMessage(HelloReply) DESCRIPTOR.has_options = True DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW')) -try: - # THESE ELEMENTS WILL BE DEPRECATED. - # Please use the generated *_pb2_grpc.py files instead. - import grpc - from grpc.framework.common import cardinality - from grpc.framework.interfaces.face import utilities as face_utilities - from grpc.beta import implementations as beta_implementations - from grpc.beta import interfaces as beta_interfaces - - - class GreeterStub(object): - """The greeting service definition. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.SayHello = channel.unary_unary( - '/helloworld.Greeter/SayHello', - request_serializer=HelloRequest.SerializeToString, - response_deserializer=HelloReply.FromString, - ) - - - class GreeterServicer(object): - """The greeting service definition. - """ - - def SayHello(self, request, context): - """Sends a greeting - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - - def add_GreeterServicer_to_server(servicer, server): - rpc_method_handlers = { - 'SayHello': grpc.unary_unary_rpc_method_handler( - servicer.SayHello, - request_deserializer=HelloRequest.FromString, - response_serializer=HelloReply.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'helloworld.Greeter', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - class BetaGreeterServicer(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """The greeting service definition. - """ - def SayHello(self, request, context): - """Sends a greeting - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - - - class BetaGreeterStub(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """The greeting service definition. - """ - def SayHello(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """Sends a greeting - """ - raise NotImplementedError() - SayHello.future = None - - - def beta_create_Greeter_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_deserializers = { - ('helloworld.Greeter', 'SayHello'): HelloRequest.FromString, - } - response_serializers = { - ('helloworld.Greeter', 'SayHello'): HelloReply.SerializeToString, - } - method_implementations = { - ('helloworld.Greeter', 'SayHello'): face_utilities.unary_unary_inline(servicer.SayHello), - } - server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) - return beta_implementations.server(method_implementations, options=server_options) - - - def beta_create_Greeter_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_serializers = { - ('helloworld.Greeter', 'SayHello'): HelloRequest.SerializeToString, - } - response_deserializers = { - ('helloworld.Greeter', 'SayHello'): HelloReply.FromString, - } - cardinalities = { - 'SayHello': cardinality.Cardinality.UNARY_UNARY, - } - stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) - return beta_implementations.dynamic_stub(channel, 'helloworld.Greeter', cardinalities, options=stub_options) -except ImportError: - pass + +_GREETER = _descriptor.ServiceDescriptor( + name='Greeter', + full_name='helloworld.Greeter', + file=DESCRIPTOR, + index=0, + options=None, + serialized_start=93, + serialized_end=166, + methods=[ + _descriptor.MethodDescriptor( + name='SayHello', + full_name='helloworld.Greeter.SayHello', + index=0, + containing_service=None, + input_type=_HELLOREQUEST, + output_type=_HELLOREPLY, + options=None, + ), +]) +_sym_db.RegisterServiceDescriptor(_GREETER) + +DESCRIPTOR.services_by_name['Greeter'] = _GREETER + # @@protoc_insertion_point(module_scope) diff --git a/examples/python/helloworld/helloworld_pb2_grpc.py b/examples/python/helloworld/helloworld_pb2_grpc.py index 682dc36cd8..18e07d1679 100644 --- a/examples/python/helloworld/helloworld_pb2_grpc.py +++ b/examples/python/helloworld/helloworld_pb2_grpc.py @@ -1,6 +1,5 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc -from grpc.framework.common import cardinality -from grpc.framework.interfaces.face import utilities as face_utilities import helloworld_pb2 as helloworld__pb2 diff --git a/examples/python/route_guide/route_guide_pb2.py b/examples/python/route_guide/route_guide_pb2.py index e6775eb814..fbbc194a58 100644 --- a/examples/python/route_guide/route_guide_pb2.py +++ b/examples/python/route_guide/route_guide_pb2.py @@ -21,7 +21,6 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_pb=_b('\n\x11route_guide.proto\x12\nrouteguide\",\n\x05Point\x12\x10\n\x08latitude\x18\x01 \x01(\x05\x12\x11\n\tlongitude\x18\x02 \x01(\x05\"I\n\tRectangle\x12\x1d\n\x02lo\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x1d\n\x02hi\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"<\n\x07\x46\x65\x61ture\x12\x0c\n\x04name\x18\x01 \x01(\t\x12#\n\x08location\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"A\n\tRouteNote\x12#\n\x08location\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x0f\n\x07message\x18\x02 \x01(\t\"b\n\x0cRouteSummary\x12\x13\n\x0bpoint_count\x18\x01 \x01(\x05\x12\x15\n\rfeature_count\x18\x02 \x01(\x05\x12\x10\n\x08\x64istance\x18\x03 \x01(\x05\x12\x14\n\x0c\x65lapsed_time\x18\x04 \x01(\x05\x32\x85\x02\n\nRouteGuide\x12\x36\n\nGetFeature\x12\x11.routeguide.Point\x1a\x13.routeguide.Feature\"\x00\x12>\n\x0cListFeatures\x12\x15.routeguide.Rectangle\x1a\x13.routeguide.Feature\"\x00\x30\x01\x12>\n\x0bRecordRoute\x12\x11.routeguide.Point\x1a\x18.routeguide.RouteSummary\"\x00(\x01\x12?\n\tRouteChat\x12\x15.routeguide.RouteNote\x1a\x15.routeguide.RouteNote\"\x00(\x01\x30\x01\x42\x36\n\x1bio.grpc.examples.routeguideB\x0fRouteGuideProtoP\x01\xa2\x02\x03RTGb\x06proto3') ) -_sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -238,6 +237,7 @@ DESCRIPTOR.message_types_by_name['Rectangle'] = _RECTANGLE DESCRIPTOR.message_types_by_name['Feature'] = _FEATURE DESCRIPTOR.message_types_by_name['RouteNote'] = _ROUTENOTE DESCRIPTOR.message_types_by_name['RouteSummary'] = _ROUTESUMMARY +_sym_db.RegisterFileDescriptor(DESCRIPTOR) Point = _reflection.GeneratedProtocolMessageType('Point', (_message.Message,), dict( DESCRIPTOR = _POINT, @@ -277,265 +277,55 @@ _sym_db.RegisterMessage(RouteSummary) DESCRIPTOR.has_options = True DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.routeguideB\017RouteGuideProtoP\001\242\002\003RTG')) -try: - # THESE ELEMENTS WILL BE DEPRECATED. - # Please use the generated *_pb2_grpc.py files instead. - import grpc - from grpc.framework.common import cardinality - from grpc.framework.interfaces.face import utilities as face_utilities - from grpc.beta import implementations as beta_implementations - from grpc.beta import interfaces as beta_interfaces - - - class RouteGuideStub(object): - """Interface exported by the server. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.GetFeature = channel.unary_unary( - '/routeguide.RouteGuide/GetFeature', - request_serializer=Point.SerializeToString, - response_deserializer=Feature.FromString, - ) - self.ListFeatures = channel.unary_stream( - '/routeguide.RouteGuide/ListFeatures', - request_serializer=Rectangle.SerializeToString, - response_deserializer=Feature.FromString, - ) - self.RecordRoute = channel.stream_unary( - '/routeguide.RouteGuide/RecordRoute', - request_serializer=Point.SerializeToString, - response_deserializer=RouteSummary.FromString, - ) - self.RouteChat = channel.stream_stream( - '/routeguide.RouteGuide/RouteChat', - request_serializer=RouteNote.SerializeToString, - response_deserializer=RouteNote.FromString, - ) - - - class RouteGuideServicer(object): - """Interface exported by the server. - """ - - def GetFeature(self, request, context): - """A simple RPC. - - Obtains the feature at a given position. - - A feature with an empty name is returned if there's no feature at the given - position. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def ListFeatures(self, request, context): - """A server-to-client streaming RPC. - - Obtains the Features available within the given Rectangle. Results are - streamed rather than returned at once (e.g. in a response message with a - repeated field), as the rectangle may cover a large area and contain a - huge number of features. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def RecordRoute(self, request_iterator, context): - """A client-to-server streaming RPC. - - Accepts a stream of Points on a route being traversed, returning a - RouteSummary when traversal is completed. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def RouteChat(self, request_iterator, context): - """A Bidirectional streaming RPC. - - Accepts a stream of RouteNotes sent while a route is being traversed, - while receiving other RouteNotes (e.g. from other users). - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - - def add_RouteGuideServicer_to_server(servicer, server): - rpc_method_handlers = { - 'GetFeature': grpc.unary_unary_rpc_method_handler( - servicer.GetFeature, - request_deserializer=Point.FromString, - response_serializer=Feature.SerializeToString, - ), - 'ListFeatures': grpc.unary_stream_rpc_method_handler( - servicer.ListFeatures, - request_deserializer=Rectangle.FromString, - response_serializer=Feature.SerializeToString, - ), - 'RecordRoute': grpc.stream_unary_rpc_method_handler( - servicer.RecordRoute, - request_deserializer=Point.FromString, - response_serializer=RouteSummary.SerializeToString, - ), - 'RouteChat': grpc.stream_stream_rpc_method_handler( - servicer.RouteChat, - request_deserializer=RouteNote.FromString, - response_serializer=RouteNote.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'routeguide.RouteGuide', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - class BetaRouteGuideServicer(object): - """The Beta API is deprecated for 0.15.0 and later. - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """Interface exported by the server. - """ - def GetFeature(self, request, context): - """A simple RPC. - - Obtains the feature at a given position. - - A feature with an empty name is returned if there's no feature at the given - position. - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def ListFeatures(self, request, context): - """A server-to-client streaming RPC. - - Obtains the Features available within the given Rectangle. Results are - streamed rather than returned at once (e.g. in a response message with a - repeated field), as the rectangle may cover a large area and contain a - huge number of features. - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def RecordRoute(self, request_iterator, context): - """A client-to-server streaming RPC. - - Accepts a stream of Points on a route being traversed, returning a - RouteSummary when traversal is completed. - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - def RouteChat(self, request_iterator, context): - """A Bidirectional streaming RPC. - - Accepts a stream of RouteNotes sent while a route is being traversed, - while receiving other RouteNotes (e.g. from other users). - """ - context.code(beta_interfaces.StatusCode.UNIMPLEMENTED) - - - class BetaRouteGuideStub(object): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This class was generated - only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.""" - """Interface exported by the server. - """ - def GetFeature(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """A simple RPC. - - Obtains the feature at a given position. - - A feature with an empty name is returned if there's no feature at the given - position. - """ - raise NotImplementedError() - GetFeature.future = None - def ListFeatures(self, request, timeout, metadata=None, with_call=False, protocol_options=None): - """A server-to-client streaming RPC. - - Obtains the Features available within the given Rectangle. Results are - streamed rather than returned at once (e.g. in a response message with a - repeated field), as the rectangle may cover a large area and contain a - huge number of features. - """ - raise NotImplementedError() - def RecordRoute(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None): - """A client-to-server streaming RPC. - - Accepts a stream of Points on a route being traversed, returning a - RouteSummary when traversal is completed. - """ - raise NotImplementedError() - RecordRoute.future = None - def RouteChat(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None): - """A Bidirectional streaming RPC. - - Accepts a stream of RouteNotes sent while a route is being traversed, - while receiving other RouteNotes (e.g. from other users). - """ - raise NotImplementedError() - - - def beta_create_RouteGuide_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): - """The Beta API is deprecated for 0.15.0 and later. - - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_deserializers = { - ('routeguide.RouteGuide', 'GetFeature'): Point.FromString, - ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.FromString, - ('routeguide.RouteGuide', 'RecordRoute'): Point.FromString, - ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString, - } - response_serializers = { - ('routeguide.RouteGuide', 'GetFeature'): Feature.SerializeToString, - ('routeguide.RouteGuide', 'ListFeatures'): Feature.SerializeToString, - ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.SerializeToString, - ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString, - } - method_implementations = { - ('routeguide.RouteGuide', 'GetFeature'): face_utilities.unary_unary_inline(servicer.GetFeature), - ('routeguide.RouteGuide', 'ListFeatures'): face_utilities.unary_stream_inline(servicer.ListFeatures), - ('routeguide.RouteGuide', 'RecordRoute'): face_utilities.stream_unary_inline(servicer.RecordRoute), - ('routeguide.RouteGuide', 'RouteChat'): face_utilities.stream_stream_inline(servicer.RouteChat), - } - server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) - return beta_implementations.server(method_implementations, options=server_options) - - - def beta_create_RouteGuide_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): - """The Beta API is deprecated for 0.15.0 and later. +_ROUTEGUIDE = _descriptor.ServiceDescriptor( + name='RouteGuide', + full_name='routeguide.RouteGuide', + file=DESCRIPTOR, + index=0, + options=None, + serialized_start=384, + serialized_end=645, + methods=[ + _descriptor.MethodDescriptor( + name='GetFeature', + full_name='routeguide.RouteGuide.GetFeature', + index=0, + containing_service=None, + input_type=_POINT, + output_type=_FEATURE, + options=None, + ), + _descriptor.MethodDescriptor( + name='ListFeatures', + full_name='routeguide.RouteGuide.ListFeatures', + index=1, + containing_service=None, + input_type=_RECTANGLE, + output_type=_FEATURE, + options=None, + ), + _descriptor.MethodDescriptor( + name='RecordRoute', + full_name='routeguide.RouteGuide.RecordRoute', + index=2, + containing_service=None, + input_type=_POINT, + output_type=_ROUTESUMMARY, + options=None, + ), + _descriptor.MethodDescriptor( + name='RouteChat', + full_name='routeguide.RouteGuide.RouteChat', + index=3, + containing_service=None, + input_type=_ROUTENOTE, + output_type=_ROUTENOTE, + options=None, + ), +]) +_sym_db.RegisterServiceDescriptor(_ROUTEGUIDE) + +DESCRIPTOR.services_by_name['RouteGuide'] = _ROUTEGUIDE - It is recommended to use the GA API (classes and functions in this - file not marked beta) for all further purposes. This function was - generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0""" - request_serializers = { - ('routeguide.RouteGuide', 'GetFeature'): Point.SerializeToString, - ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.SerializeToString, - ('routeguide.RouteGuide', 'RecordRoute'): Point.SerializeToString, - ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString, - } - response_deserializers = { - ('routeguide.RouteGuide', 'GetFeature'): Feature.FromString, - ('routeguide.RouteGuide', 'ListFeatures'): Feature.FromString, - ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.FromString, - ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString, - } - cardinalities = { - 'GetFeature': cardinality.Cardinality.UNARY_UNARY, - 'ListFeatures': cardinality.Cardinality.UNARY_STREAM, - 'RecordRoute': cardinality.Cardinality.STREAM_UNARY, - 'RouteChat': cardinality.Cardinality.STREAM_STREAM, - } - stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) - return beta_implementations.dynamic_stub(channel, 'routeguide.RouteGuide', cardinalities, options=stub_options) -except ImportError: - pass # @@protoc_insertion_point(module_scope) diff --git a/examples/python/route_guide/route_guide_pb2_grpc.py b/examples/python/route_guide/route_guide_pb2_grpc.py index 27b24c747d..05c1b79312 100644 --- a/examples/python/route_guide/route_guide_pb2_grpc.py +++ b/examples/python/route_guide/route_guide_pb2_grpc.py @@ -1,6 +1,5 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc -from grpc.framework.common import cardinality -from grpc.framework.interfaces.face import utilities as face_utilities import route_guide_pb2 as route__guide__pb2 |