aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/cpp/helloworld/Makefile7
-rw-r--r--examples/cpp/helloworld/greeter_async_client.cc8
-rw-r--r--examples/cpp/helloworld/greeter_async_client2.cc153
-rw-r--r--examples/objective-c/route_guide/ViewControllers.m89
-rw-r--r--examples/python/helloworld/helloworld_pb2.py73
-rw-r--r--examples/python/route_guide/route_guide_pb2.py189
6 files changed, 305 insertions, 214 deletions
diff --git a/examples/cpp/helloworld/Makefile b/examples/cpp/helloworld/Makefile
index 470b83573e..58a82dbb83 100644
--- a/examples/cpp/helloworld/Makefile
+++ b/examples/cpp/helloworld/Makefile
@@ -41,7 +41,7 @@ PROTOS_PATH = ../../protos
vpath %.proto $(PROTOS_PATH)
-all: system-check greeter_client greeter_server greeter_async_client greeter_async_server
+all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server
greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
$(CXX) $^ $(LDFLAGS) -o $@
@@ -52,6 +52,9 @@ greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o
greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o
$(CXX) $^ $(LDFLAGS) -o $@
+greeter_async_client2: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client2.o
+ $(CXX) $^ $(LDFLAGS) -o $@
+
greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o
$(CXX) $^ $(LDFLAGS) -o $@
@@ -64,7 +67,7 @@ greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.
$(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
clean:
- rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_server
+ rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server
# The following is to test your system and ensure a smoother experience.
diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc
index 35014267fe..c1f5eb55f0 100644
--- a/examples/cpp/helloworld/greeter_async_client.cc
+++ b/examples/cpp/helloworld/greeter_async_client.cc
@@ -53,7 +53,7 @@ class GreeterClient {
explicit GreeterClient(std::shared_ptr<Channel> channel)
: stub_(Greeter::NewStub(channel)) {}
- // Assambles the client's payload, sends it and presents the response back
+ // Assembles the client's payload, sends it and presents the response back
// from the server.
std::string SayHello(const std::string& user) {
// Data we are sending to the server.
@@ -74,9 +74,9 @@ class GreeterClient {
// Storage for the status of the RPC upon completion.
Status status;
- // stub_->AsyncSayHello() perform the RPC call, returning an instance we
- // store in "rpc". Because we are using the asynchronous API, we need the
- // hold on to the "rpc" instance in order to get updates on the ongoig RPC.
+ // stub_->AsyncSayHello() performs the RPC call, returning an instance we
+ // store in "rpc". Because we are using the asynchronous API, we need to
+ // hold on to the "rpc" instance in order to get updates on the ongoing RPC.
std::unique_ptr<ClientAsyncResponseReader<HelloReply> > rpc(
stub_->AsyncSayHello(&context, request, &cq));
diff --git a/examples/cpp/helloworld/greeter_async_client2.cc b/examples/cpp/helloworld/greeter_async_client2.cc
new file mode 100644
index 0000000000..0902376074
--- /dev/null
+++ b/examples/cpp/helloworld/greeter_async_client2.cc
@@ -0,0 +1,153 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include <grpc++/grpc++.h>
+#include <thread>
+
+#include "helloworld.grpc.pb.h"
+
+using grpc::Channel;
+using grpc::ClientAsyncResponseReader;
+using grpc::ClientContext;
+using grpc::CompletionQueue;
+using grpc::Status;
+using helloworld::HelloRequest;
+using helloworld::HelloReply;
+using helloworld::Greeter;
+
+class GreeterClient {
+ public:
+ explicit GreeterClient(std::shared_ptr<Channel> channel)
+ : stub_(Greeter::NewStub(channel)) {}
+
+ // Assembles the client's payload and sends it to the server.
+ void SayHello(const std::string& user) {
+ // Data we are sending to the server.
+ HelloRequest request;
+ request.set_name(user);
+
+ // Call object to store rpc data
+ AsyncClientCall* call = new AsyncClientCall;
+
+ // stub_->AsyncSayHello() performs the RPC call, returning an instance to
+ // store in "call". Because we are using the asynchronous API, we need to
+ // hold on to the "call" instance in order to get updates on the ongoing RPC.
+ call->response_reader = stub_->AsyncSayHello(&call->context, request, &cq_);
+
+
+ // Request that, upon completion of the RPC, "reply" be updated with the
+ // server's response; "status" with the indication of whether the operation
+ // was successful. Tag the request with the memory address of the call object.
+ call->response_reader->Finish(&call->reply, &call->status, (void*)call);
+
+ }
+
+ // Loop while listening for completed responses.
+ // Prints out the response from the server.
+ void AsyncCompleteRpc() {
+ void* got_tag;
+ bool ok = false;
+
+ // Block until the next result is available in the completion queue "cq".
+ while (cq_.Next(&got_tag, &ok)) {
+ // The tag in this example is the memory location of the call object
+ AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);
+
+ // Verify that the request was completed successfully. Note that "ok"
+ // corresponds solely to the request for updates introduced by Finish().
+ GPR_ASSERT(ok);
+
+ if (call->status.ok())
+ std::cout << "Greeter received: " << call->reply.message() << std::endl;
+ else
+ std::cout << "RPC failed" << std::endl;
+
+ // Once we're complete, deallocate the call object.
+ delete call;
+ }
+ }
+
+ private:
+
+ // struct for keeping state and data information
+ struct AsyncClientCall {
+ // Container for the data we expect from the server.
+ HelloReply reply;
+
+ // Context for the client. It could be used to convey extra information to
+ // the server and/or tweak certain RPC behaviors.
+ ClientContext context;
+
+ // Storage for the status of the RPC upon completion.
+ Status status;
+
+
+ std::unique_ptr<ClientAsyncResponseReader<HelloReply>> response_reader;
+ };
+
+ // Out of the passed in Channel comes the stub, stored here, our view of the
+ // server's exposed services.
+ std::unique_ptr<Greeter::Stub> stub_;
+
+ // The producer-consumer queue we use to communicate asynchronously with the
+ // gRPC runtime.
+ CompletionQueue cq_;
+};
+
+int main(int argc, char** argv) {
+
+
+ // Instantiate the client. It requires a channel, out of which the actual RPCs
+ // are created. This channel models a connection to an endpoint (in this case,
+ // localhost at port 50051). We indicate that the channel isn't authenticated
+ // (use of InsecureChannelCredentials()).
+ GreeterClient greeter(grpc::CreateChannel(
+ "localhost:50051", grpc::InsecureChannelCredentials()));
+
+ // Spawn reader thread that loops indefinitely
+ std::thread thread_ = std::thread(&GreeterClient::AsyncCompleteRpc, &greeter);
+
+ for (int i = 0; i < 100; i++) {
+ std::string user("world " + std::to_string(i));
+ greeter.SayHello(user); // The actual RPC call!
+ }
+
+ std::cout << "Press control-c to quit" << std::endl << std::endl;
+ thread_.join(); //blocks forever
+
+ return 0;
+}
diff --git a/examples/objective-c/route_guide/ViewControllers.m b/examples/objective-c/route_guide/ViewControllers.m
index 0b1a1cf482..e32978240b 100644
--- a/examples/objective-c/route_guide/ViewControllers.m
+++ b/examples/objective-c/route_guide/ViewControllers.m
@@ -80,19 +80,14 @@ static NSString * const kHostAddress = @"localhost:50051";
* Run the getFeature demo. Calls getFeature with a point known to have a feature and a point known
* not to have a feature.
*/
-@interface GetFeatureViewController : UIViewController
+@interface GetFeatureViewController : UIViewController {
+ RTGRouteGuide *service;
+}
@end
@implementation GetFeatureViewController
-- (void)viewDidLoad {
- [super viewDidLoad];
-
- // This only needs to be done once per host, before creating service objects for that host.
- [GRPCCall useInsecureConnectionsForHost:kHostAddress];
-
- RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
-
+- (void)execRequest {
void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) {
if (response.name.length) {
NSLog(@"Found feature called %@ at %@.", response.name, response.location);
@@ -111,6 +106,19 @@ static NSString * const kHostAddress = @"localhost:50051";
[service getFeatureWithRequest:[RTGPoint message] handler:handler];
}
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // This only needs to be done once per host, before creating service objects for that host.
+ [GRPCCall useInsecureConnectionsForHost:kHostAddress];
+
+ service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [self execRequest];
+}
+
@end
@@ -120,16 +128,15 @@ static NSString * const kHostAddress = @"localhost:50051";
* Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in
* the pre-generated database. Prints each response as it comes in.
*/
-@interface ListFeaturesViewController : UIViewController
+@interface ListFeaturesViewController : UIViewController {
+ RTGRouteGuide *service;
+}
+
@end
@implementation ListFeaturesViewController
-- (void)viewDidLoad {
- [super viewDidLoad];
-
- RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
-
+- (void)execRequest {
RTGRectangle *rectangle = [RTGRectangle message];
rectangle.lo.latitude = 405E6;
rectangle.lo.longitude = -750E6;
@@ -147,6 +154,16 @@ static NSString * const kHostAddress = @"localhost:50051";
}];
}
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [self execRequest];
+}
+
@end
@@ -157,14 +174,15 @@ static NSString * const kHostAddress = @"localhost:50051";
* database with a variable delay in between. Prints the statistics when they are sent from the
* server.
*/
-@interface RecordRouteViewController : UIViewController
+@interface RecordRouteViewController : UIViewController {
+ RTGRouteGuide *service;
+}
+
@end
@implementation RecordRouteViewController
-- (void)viewDidLoad {
- [super viewDidLoad];
-
+- (void)execRequest {
NSString *dataBasePath = [NSBundle.mainBundle pathForResource:@"route_guide_db"
ofType:@"json"];
NSData *dataBaseContent = [NSData dataWithContentsOfFile:dataBasePath];
@@ -178,8 +196,6 @@ static NSString * const kHostAddress = @"localhost:50051";
return location;
}];
- RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
-
[service recordRouteWithRequestsWriter:locations
handler:^(RTGRouteSummary *response, NSError *error) {
if (response) {
@@ -193,6 +209,16 @@ static NSString * const kHostAddress = @"localhost:50051";
}];
}
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [self execRequest];
+}
+
@end
@@ -202,14 +228,15 @@ static NSString * const kHostAddress = @"localhost:50051";
* Run the routeChat demo. Send some chat messages, and print any chat messages that are sent from
* the server.
*/
-@interface RouteChatViewController : UIViewController
+@interface RouteChatViewController : UIViewController {
+ RTGRouteGuide *service;
+}
+
@end
@implementation RouteChatViewController
-- (void)viewDidLoad {
- [super viewDidLoad];
-
+- (void)execRequest {
NSArray *notes = @[[RTGRouteNote noteWithMessage:@"First message" latitude:0 longitude:0],
[RTGRouteNote noteWithMessage:@"Second message" latitude:0 longitude:1],
[RTGRouteNote noteWithMessage:@"Third message" latitude:1 longitude:0],
@@ -219,8 +246,6 @@ static NSString * const kHostAddress = @"localhost:50051";
return note;
}];
- RTGRouteGuide *service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
-
[service routeChatWithRequestsWriter:notesWriter
eventHandler:^(BOOL done, RTGRouteNote *note, NSError *error) {
if (note) {
@@ -234,4 +259,14 @@ static NSString * const kHostAddress = @"localhost:50051";
}];
}
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ service = [[RTGRouteGuide alloc] initWithHost:kHostAddress];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [self execRequest];
+}
+
@end
diff --git a/examples/python/helloworld/helloworld_pb2.py b/examples/python/helloworld/helloworld_pb2.py
index 1b2674e4c8..1ee80e4034 100644
--- a/examples/python/helloworld/helloworld_pb2.py
+++ b/examples/python/helloworld/helloworld_pb2.py
@@ -1,6 +1,8 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: helloworld.proto
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
@@ -17,7 +19,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
name='helloworld.proto',
package='helloworld',
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\x18\n\x10io.grpc.examples\xa2\x02\x03HLWb\x06proto3'
+ 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)
@@ -34,7 +36,7 @@ _HELLOREQUEST = _descriptor.Descriptor(
_descriptor.FieldDescriptor(
name='name', full_name='helloworld.HelloRequest.name', index=0,
number=1, type=9, cpp_type=9, label=1,
- has_default_value=False, default_value=b"".decode('utf-8'),
+ has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@@ -65,7 +67,7 @@ _HELLOREPLY = _descriptor.Descriptor(
_descriptor.FieldDescriptor(
name='message', full_name='helloworld.HelloReply.message', index=0,
number=1, type=9, cpp_type=9, label=1,
- has_default_value=False, default_value=b"".decode('utf-8'),
+ has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@@ -104,69 +106,28 @@ _sym_db.RegisterMessage(HelloReply)
DESCRIPTOR.has_options = True
-DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), b'\n\020io.grpc.examples\242\002\003HLW')
+DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.helloworldB\017HelloWorldProtoP\001\242\002\003HLW'))
import abc
+import six
from grpc.beta import implementations as beta_implementations
-from grpc.early_adopter import implementations as early_adopter_implementations
-from grpc.framework.alpha import utilities as alpha_utilities
+from grpc.beta import interfaces as beta_interfaces
from grpc.framework.common import cardinality
from grpc.framework.interfaces.face import utilities as face_utilities
-class EarlyAdopterGreeterServicer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def SayHello(self, request, context):
- raise NotImplementedError()
-class EarlyAdopterGreeterServer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def start(self):
- raise NotImplementedError()
- @abc.abstractmethod
- def stop(self):
- raise NotImplementedError()
-class EarlyAdopterGreeterStub(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def SayHello(self, request):
- raise NotImplementedError()
- SayHello.async = None
-def early_adopter_create_Greeter_server(servicer, port, private_key=None, certificate_chain=None):
- import helloworld_pb2
- import helloworld_pb2
- method_service_descriptions = {
- "SayHello": alpha_utilities.unary_unary_service_description(
- servicer.SayHello,
- helloworld_pb2.HelloRequest.FromString,
- helloworld_pb2.HelloReply.SerializeToString,
- ),
- }
- return early_adopter_implementations.server("helloworld.Greeter", method_service_descriptions, port, private_key=private_key, certificate_chain=certificate_chain)
-def early_adopter_create_Greeter_stub(host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, server_host_override=None):
- import helloworld_pb2
- import helloworld_pb2
- method_invocation_descriptions = {
- "SayHello": alpha_utilities.unary_unary_invocation_description(
- helloworld_pb2.HelloRequest.SerializeToString,
- helloworld_pb2.HelloReply.FromString,
- ),
- }
- return early_adopter_implementations.stub("helloworld.Greeter", method_invocation_descriptions, host, port, metadata_transformer=metadata_transformer, secure=secure, root_certificates=root_certificates, private_key=private_key, certificate_chain=certificate_chain, server_host_override=server_host_override)
class BetaGreeterServicer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
+ """The greeting service definition.
+ """
def SayHello(self, request, context):
- raise NotImplementedError()
+ """Sends a greeting
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
class BetaGreeterStub(object):
- """The interface to which stubs will conform."""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
+ """The greeting service definition.
+ """
def SayHello(self, request, timeout):
+ """Sends a greeting
+ """
raise NotImplementedError()
SayHello.future = None
diff --git a/examples/python/route_guide/route_guide_pb2.py b/examples/python/route_guide/route_guide_pb2.py
index d4d9f8dcd5..81d5d07527 100644
--- a/examples/python/route_guide/route_guide_pb2.py
+++ b/examples/python/route_guide/route_guide_pb2.py
@@ -1,6 +1,8 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: route_guide.proto
+import sys
+_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
@@ -17,7 +19,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
name='route_guide.proto',
package='routeguide',
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\x0f\n\x07\x65x.grpc\xa2\x02\x03RTGb\x06proto3'
+ 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)
@@ -110,7 +112,7 @@ _FEATURE = _descriptor.Descriptor(
_descriptor.FieldDescriptor(
name='name', full_name='routeguide.Feature.name', index=0,
number=1, type=9, cpp_type=9, label=1,
- has_default_value=False, default_value=b"".decode('utf-8'),
+ has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@@ -155,7 +157,7 @@ _ROUTENOTE = _descriptor.Descriptor(
_descriptor.FieldDescriptor(
name='message', full_name='routeguide.RouteNote.message', index=1,
number=2, type=9, cpp_type=9, label=1,
- has_default_value=False, default_value=b"".decode('utf-8'),
+ has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
@@ -274,149 +276,86 @@ _sym_db.RegisterMessage(RouteSummary)
DESCRIPTOR.has_options = True
-DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), b'\n\007ex.grpc\242\002\003RTG')
+DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.routeguideB\017RouteGuideProtoP\001\242\002\003RTG'))
import abc
+import six
from grpc.beta import implementations as beta_implementations
-from grpc.early_adopter import implementations as early_adopter_implementations
-from grpc.framework.alpha import utilities as alpha_utilities
+from grpc.beta import interfaces as beta_interfaces
from grpc.framework.common import cardinality
from grpc.framework.interfaces.face import utilities as face_utilities
-class EarlyAdopterRouteGuideServicer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def GetFeature(self, request, context):
- raise NotImplementedError()
- @abc.abstractmethod
- def ListFeatures(self, request, context):
- raise NotImplementedError()
- @abc.abstractmethod
- def RecordRoute(self, request_iterator, context):
- raise NotImplementedError()
- @abc.abstractmethod
- def RouteChat(self, request_iterator, context):
- raise NotImplementedError()
-class EarlyAdopterRouteGuideServer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def start(self):
- raise NotImplementedError()
- @abc.abstractmethod
- def stop(self):
- raise NotImplementedError()
-class EarlyAdopterRouteGuideStub(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
- def GetFeature(self, request):
- raise NotImplementedError()
- GetFeature.async = None
- @abc.abstractmethod
- def ListFeatures(self, request):
- raise NotImplementedError()
- ListFeatures.async = None
- @abc.abstractmethod
- def RecordRoute(self, request_iterator):
- raise NotImplementedError()
- RecordRoute.async = None
- @abc.abstractmethod
- def RouteChat(self, request_iterator):
- raise NotImplementedError()
- RouteChat.async = None
-def early_adopter_create_RouteGuide_server(servicer, port, private_key=None, certificate_chain=None):
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- method_service_descriptions = {
- "GetFeature": alpha_utilities.unary_unary_service_description(
- servicer.GetFeature,
- route_guide_pb2.Point.FromString,
- route_guide_pb2.Feature.SerializeToString,
- ),
- "ListFeatures": alpha_utilities.unary_stream_service_description(
- servicer.ListFeatures,
- route_guide_pb2.Rectangle.FromString,
- route_guide_pb2.Feature.SerializeToString,
- ),
- "RecordRoute": alpha_utilities.stream_unary_service_description(
- servicer.RecordRoute,
- route_guide_pb2.Point.FromString,
- route_guide_pb2.RouteSummary.SerializeToString,
- ),
- "RouteChat": alpha_utilities.stream_stream_service_description(
- servicer.RouteChat,
- route_guide_pb2.RouteNote.FromString,
- route_guide_pb2.RouteNote.SerializeToString,
- ),
- }
- return early_adopter_implementations.server("routeguide.RouteGuide", method_service_descriptions, port, private_key=private_key, certificate_chain=certificate_chain)
-def early_adopter_create_RouteGuide_stub(host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, server_host_override=None):
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- import route_guide_pb2
- method_invocation_descriptions = {
- "GetFeature": alpha_utilities.unary_unary_invocation_description(
- route_guide_pb2.Point.SerializeToString,
- route_guide_pb2.Feature.FromString,
- ),
- "ListFeatures": alpha_utilities.unary_stream_invocation_description(
- route_guide_pb2.Rectangle.SerializeToString,
- route_guide_pb2.Feature.FromString,
- ),
- "RecordRoute": alpha_utilities.stream_unary_invocation_description(
- route_guide_pb2.Point.SerializeToString,
- route_guide_pb2.RouteSummary.FromString,
- ),
- "RouteChat": alpha_utilities.stream_stream_invocation_description(
- route_guide_pb2.RouteNote.SerializeToString,
- route_guide_pb2.RouteNote.FromString,
- ),
- }
- return early_adopter_implementations.stub("routeguide.RouteGuide", method_invocation_descriptions, host, port, metadata_transformer=metadata_transformer, secure=secure, root_certificates=root_certificates, private_key=private_key, certificate_chain=certificate_chain, server_host_override=server_host_override)
class BetaRouteGuideServicer(object):
- """<fill me in later!>"""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
+ """Interface exported by the server.
+ """
def GetFeature(self, request, context):
- raise NotImplementedError()
- @abc.abstractmethod
+ """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):
- raise NotImplementedError()
- @abc.abstractmethod
+ """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):
- raise NotImplementedError()
- @abc.abstractmethod
+ """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):
- raise NotImplementedError()
+ """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 interface to which stubs will conform."""
- __metaclass__ = abc.ABCMeta
- @abc.abstractmethod
+ """Interface exported by the server.
+ """
def GetFeature(self, request, timeout):
+ """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
- @abc.abstractmethod
def ListFeatures(self, request, timeout):
+ """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()
- @abc.abstractmethod
def RecordRoute(self, request_iterator, timeout):
+ """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
- @abc.abstractmethod
def RouteChat(self, request_iterator, timeout):
+ """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):